Haraka na Easy: Kupata SPFolder ya SPItemList

Naendelea mbio katika tatizo hili na Google kamwe inaonekana kuelewa nini nataka kufanya, hivyo mimi figured napenda kuandika hii chini.

Nimekuwa kufanya mengi ya tukio debugging receiver katika wiki ya mwisho au mbili. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. Hivyo, I am always getting the folder of the item for various manipulations. While debugging, Mimi zinahitajika update metadata ya folder kwa bidhaa maalum ambao ID najua.

Hapa ni kidogo console maombi (iliyoundwa na kukimbia katika server katika kilimo) kwamba inachukua hoja mbili: ID ya bidhaa na thamani hawawajui shamba, "Approval Status". It hard codes a lot of stuff and has no error checking.

kanuni inaonekana hadi ngumu coded tovuti, 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.

Kama mtu yeyote anayejali kutoa kukosoa au kupendekeza njia bora ya kupata folder ya bidhaa, tafadhali acha maoni.

<kanuni>
kutumia Mfumo;
kutumia System.Collections.Generic;
kutumia System.Text;
kutumia Microsoft.SharePoint;
kutumia System.Collections;

namespace Conchango
{
    /// <muhtasari>
 /// </muhtasari>
 darasani ManualFolderUpdate
    {
        tuli utupu Kuu(string[] args)
        {
            string msh = "ManualFolderUpdate (v1.0): "; // msh = "Message Header"

 Kuwafariji.WriteLine(msh + "Starting up.  Mimi mara ya mwisho tarehe 08/04/08.");

            string url = http://localhost/xyzzy;

            kutumia (SPSite oSPSite = mpya SPSite(url))
            {

                kutumia (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                    SPList docLib = oSPWeb.Lists["Documents"];

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

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

                    int FolderID = 0;
                    string NewStatus = "xyzzy";

                    FolderID = System.Kubadilisha.ToInt32(args[0].ToString());
                    Kuwafariji.WriteLine("Seeking folder for item: [" + FolderID + "].");

                    SPListItem li = docLib.GetItemById(FolderID);

                    SPFolder thisItemFolder = li.File.ParentFolder;

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

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

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

                    Kuwafariji.ReadLine();

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

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

                } // kutumia SPWeb

            } // kutumia SPSite

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

        } // Kuu

    } // darasani foldersync
} // namespace
</kanuni>

</mwisho>

Kujiunga na blog yangu.

Tags technorati:

Kuondoka Reply

Anwani yako si kuchapishwa. Mashamba required ni alama *