Tez və asan: SPItemList və SPFolder almaq

Mən istəyirəm, hansı ki, bu problem daxil yayınlanmaya davam və Google anlamaq üçün görünür heç, belə mən bu yazır ki, fiqurlu.

Mən keçən həftə və ya iki hadisə qəbuledici ayıklama bir çox məşğul olduğunuz. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. Belə, I am always getting the folder of the item for various manipulations. While debugging, Mən kimin ID bilirəm xüsusi bir maddə üçün bir qovluq metadata yeniləmək üçün lazım.

Burada bir az konsol ərizənin (çiftlikte server yayınlanması nəzərdə) iki dəlilləri edir: obyektinin şəxsiyyət və bir sahəyə təyin etmək dəyəri, "Approval Status". It hard codes a lot of stuff and has no error checking.

Kodu ağır kodlu site görünür, 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.

Hər bir tənqid təklif və ya obyektinin qovluğu almaq üçün daha yaxşı bir yol təklif umurunda əgər, Şərh tərk edin.

<kod>
istifadə Sistem;
istifadə System.Collections.Generic;
istifadə System.Text;
istifadə Microsoft.SharePoint;
istifadə System.Collections;

Adlar fəzası Conchango
{
    /// <xülasə>
 /// </xülasə>
 sinfi ManualFolderUpdate
    {
        statik ləğv Əsas(sim[] args)
        {
            sim msh = "ManualFolderUpdate (v1.0): "; // msh = "Message Header"

 Təsəlli.WriteLine(msh + "Starting up.  Son 08/04/08 tarixində redaktə edilib.");

            sim url = http://localhost/xyzzy;

            istifadə (SPSite oSPSite = yeni SPSite(url))
            {

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

                    Təsəlli.WriteLine(msh + "Got the document library.");

                    Təsəlli.WriteLine(msh + "Doc lib item count: [" + docLib.ItemCount + "].");

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

                    FolderID = Sistemi.Çevirmək.ToInt32(args[0].ToString());
                    Təsəlli.WriteLine("Seeking folder for item: [" + FolderID + "].");

                    SPListItem li = docLib.GetItemById(FolderID);

                    SPFolder thisItemFolder = li.File.ParentFolder;

                    Təsəlli.WriteLine(msh + "Got the parent folder.");

                    NewStatus = args[1].ToString();
                    Təsəlli.WriteLine("Setting status to [" + NewStatus + "].");

                    Təsəlli.WriteLine("Press return to commit the update or CTRL-C to abort.");

                    Təsəlli.ReadLine();

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

                    Təsəlli.WriteLine(msh + "Finished updating the folder.  Mövcud.");

                } // SPWeb istifadə

            } // SPSite istifadə

 Təsəlli.WriteLine(msh + "Finished.");

        } // Əsas

    } // sinif foldersync
} // Adlar fəzası
</kod>

</son>

Blog abunə.

Şəkil Yükləmə

E-poçt ünvanından dərc olunmayacaq. Lazım alanlar qeyd olunur *