სწრაფი და მარტივი: მიიღეთ SPFolder of SPItemList

მე შენარჩუნება გაშვებული შევიდა ეს პრობლემა და Google არასოდეს, როგორც ჩანს, მიხვდა, თუ რა მინდა, ამიტომ მე figured მინდა დაწერა ამ ქვემოთ.

მე აკეთებდა ბევრი ღონისძიება მიმღები გამართვის, ბოლო ორი კვირის. 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.Collections.Generic;
გამოყენებით System.Text;
გამოყენებით Microsoft.SharePoint;
გამოყენებით System.Collections;

სახელების სივრცე Conchango
{
    /// <შემაჯამებელი>
 /// </შემაჯამებელი>
 კლასი ManualFolderUpdate
    {
        სტატიკური ცნოს მთავარი(სიმებიანი[] 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 + "].");

                    int FolderID = 0;
                    სიმებიანი NewStatus = "xyzzy";

                    FolderID = System.Convert.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.");

        } // მთავარი

    } // class foldersync
} // სახელების სივრცე
</code>

</ბოლო>

გამოწერა ჩემი დღიური.

პროგრამები Tags:

დატოვე პასუხი

თქვენი ელ-ფოსტა არ გამოქვეყნდება. აუცილებელი ველები მონიშნულია *