Azkarra eta erraza: Talde SPItemList de SPFolder

Arazo hau sartu jarraitzen dut martxan eta Google inoiz badirudi ulertzen zer egin nahi dut, beraz, behera hau idazten nuke figured dut.

Izan dut gertaera hartzailea arazketa asko egiten ari da azken aste edo bi. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. Beraz,, I am always getting the folder of the item for various manipulations. While debugging, Karpeta bat metadatuak eguneratu elementu zehatz bat eta haren identifikazio dut jakin behar nuen.

Hemen pixka bat kontsola aplikazio bat da (diseinatutako zerbitzari exekutatzen etxalde batean) hartzen duten bi argumentu: elementu bati identifikazio eta balio bat behar eremu bat esleitu, "Approval Status". It hard codes a lot of stuff and has no error checking.

Kodearen begiratuko gogor kodetuak gune, 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.

Edozeinek zaintzen kritika bat eskaintzeko, edo hobeto elementu bat karpeta lortzeko iradokitzen bada, Mesedez, utzi iruzkin bat.

<kodea>
erabiliz Sistema;
erabiliz System.Collections.Generic;
erabiliz System.Text;
erabiliz Microsoft.SharePoint;
erabiliz System.Collections;

namespace Conchango
{
    /// <laburpena>
 /// </laburpena>
 klasean ManualFolderUpdate
    {
        estatiko gal Nagusia(katea[] argumentuak)
        {
            katea msh = "ManualFolderUpdate (v1.0): "; // msh = "Message Header"

 Kontsolara.WriteLine(msh + "Starting up.  Nintzen azken aldaketa: 08/04/08.");

            katea url = http://localhost/xyzzy;

            erabiliz (SPSite oSPSite = berria SPSite(url))
            {

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

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

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

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

                    FolderID = Sistema.Bihurtu.ToInt32(argumentuak[0].ToString());
                    Kontsolara.WriteLine("Seeking folder for item: [" + FolderID + "].");

                    SPListItem li = docLib.GetItemById(FolderID);

                    SPFolder thisItemFolder = li.File.ParentFolder;

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

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

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

                    Kontsolara.ReadLine();

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

                    Kontsolara.WriteLine(msh + "Finished updating the folder.  Irteten.");

                } // SPWeb erabiliz

            } // SPSite erabiliz

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

        } // Nagusia

    } // klase foldersync
} // namespace
</kodea>

</amaiera>

Nire blog Harpidetu.

Technorati Tags:

Utzi iruzkin bat

Zure e-posta helbidea ez da argitaratuko. Beharrezko eremuak markatu dira *