I iżommu taħdem fis din il-problema u l-Google qatt ma jidher li jifhmu dak I trid tagħmel, so I dehret I se jikteb din stabbiliti.
Stajt kont qed tagħmel ħafna ta 'debugging riċevitur avveniment fl-aħħar ġimgħa jew tnejn. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. Allura, 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, jekk jogħġbok leave kumment.
<code>
użu Sistema; użu System.Collections.Generic; użu System.Text; użu Microsoft.SharePoint; użu System.Collections; namespace Conchango { /// <sommarju> /// </sommarju> klassi ManualFolderUpdate { statiku null Main(string[] args) { string msh = "ManualFolderUpdate (v1.0): "; // msh = "Message Header" Console.WriteLine(msh + "Starting up. I was last modified on 08/04/08."); string url = http://localhost/xyzzy; użu (SPSite oSPSite = ġdid SPSite(url)) { użu (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; string NewStatus = "xyzzy"; FolderID = System.Ikkonverti.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>
</aħħar>