ತ್ವರಿತ ಮತ್ತು ಸುಲಭ: SPItemList ಆಫ್ SPFolder ಪಡೆಯಿರಿ

ನಾನು ಯಾವ ನಾನು ಈ ಸಮಸ್ಯೆಯನ್ನು ಇಟ್ಟಿರಿ ಮತ್ತು ಗೂಗಲ್ ಅರ್ಥ ತೋರುತ್ತದೆ ಎಂದಿಗೂ, ಆದ್ದರಿಂದ ನಾನು ಈ ಕೆಳಗೆ ಬರೆಯಬಹುದು ಕಾಣಿಸಿಕೊಂಡಿತ್ತು.

ನಾನು ಕಳೆದ ವಾರ ಅಥವಾ ಎರಡು ಈವೆಂಟ್ ರಿಸೀವರ್ ಡೀಬಗ್ ಸಾಕಷ್ಟು ಮಾಡುವುದರಿಂದ ನಾವು. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. ಆದ್ದರಿಂದ, I am always getting the folder of the item for various manipulations. While debugging, I needed to update the metadata of a folder for a specific item whose ID I know.

Here’s a little console application (designed to run on server in the farm) that takes two arguments: the ID of an item and a value to assign to a field, "Approval Status". It hard codes a lot of stuff and has no error checking.

The code looks up a hard coded site, gets a hard coded document library and then finds the indicated item. It then finds the parent folder of that item and assigns the status value.

The key lesson here for me is that SPItem doesn’t get you access to the folder. You need to use SPListItem.File.

If anyone cares to offer a critique or suggest a better way to get the folder of an item, ಪ್ರತಿಕ್ರಿಯೆ ನೀಡಿ.

<code>
ಬಳಸಿ System;
ಬಳಸಿ System.Collections.Generic;
ಬಳಸಿ System.Text;
ಬಳಸಿ Microsoft.SharePoint;
ಬಳಸಿ System.Collections;

namespace Conchango
{
    /// <ಸಂಗ್ರಹವಾದ>
 /// </ಸಂಗ್ರಹವಾದ>
 ವರ್ಗ ManualFolderUpdate
    {
        ಸ್ಥಿರ ಶೂನ್ಯವಾಗುವ Main(ದಾರ[] args)
        {
            ದಾರ msh = "ManualFolderUpdate (v1.0): "; // msh = "Message Header"

 Console.WriteLine(msh + "Starting up.  I was last modified on 08/04/08.");

            ದಾರ url = http://localhost/xyzzy;

            ಬಳಸಿ (SPSite oSPSite = ಹೊಸ SPSite(URL))
            {

                ಬಳಸಿ (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                    SPList docLib = oSPWeb.Lists["Documents"];

                    Console.WriteLine(msh + "Got the document library.");

                    Console.WriteLine(msh + "Doc lib item count: [" + docLib.ItemCount + "].");

                    ಇಂಟ್ FolderID = 0;
                    ದಾರ NewStatus = "xyzzy";

                    FolderID = System.ಪರಿವರ್ತಿಸಿ.ToInt32(args[0].ToString());
                    Console.WriteLine("Seeking folder for item: [" + FolderID + "].");

                    SPListItem li = docLib.GetItemById(FolderID);

                    SPFolder thisItemFolder = li.File.ParentFolder;

                    Console.WriteLine(msh + "Got the parent folder.");

                    NewStatus = args[1].ToString();
                    Console.WriteLine("Setting status to [" + NewStatus + "].");

                    Console.WriteLine("Press return to commit the update or CTRL-C to abort.");

                    Console.ReadLine();

                    thisItemFolder.Item["Approval Status"] = NewStatus;
                    thisItemFolder.Item.Update();

                    Console.WriteLine(msh + "Finished updating the folder.  Exiting.");

                } // using SPWeb

            } // using SPSite

 Console.WriteLine(msh + "Finished.");

        } // Main

    } // class foldersync
} // namespace
</code>

</ಕೊನೆಯಲ್ಲಿ>

ನನ್ನ ಬ್ಲಾಗ್ ಚಂದಾದಾರರಾಗಿ.

ನನ್ನ ಟ್ಯಾಗ್ಗಳು:

ಒಂದು ಉತ್ತರಿಸಿ ಬಿಡಿ

ನಿಮ್ಮ ಈಮೇಲ್ ವಿಳಾಸ ರ ಆಗುವುದಿಲ್ಲ. ಅಗತ್ಯವಿರುವ ಜಾಗ ಗುರುತಿಸಲಾಗಿದೆ *