Tapaidh agus éasca: Faigh SPFolder de SPItemList

Mé a choinneáil ag rith isteach ar an bhfadhb agus an Google is cosúil riamh a thuiscint cad ba mhaith liom a dhéanamh, mar sin figured mé ba mhaith liom a scríobh síos an.

Tá mé ag déanamh a lán de na debugging glacadóir ócáid ​​sa tseachtain seo caite nó dhó. The ER is defined against a document library. The individual items in the document library are tightly related to their parent folders. Mar sin,, I am always getting the folder of the item for various manipulations. While debugging, Is gá dom a thabhairt cothrom le dáta na meiteashonraí de fillteán le mír shonrach a bhfuil a haitheantas a fhios agam.

Seo iarratas consól beag (a ceapadh chun reáchtáil ar an bhfreastalaí sa feirme) a thógann dhá argóint: an ID mír agus luach a shannadh do réimse, "Approval Status". It hard codes a lot of stuff and has no error checking.

Breathnaíonn an cód suas láithreán códaithe crua, 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.

Má cares duine ar bith a thairiscint le léirmheas nó tuiscint ar bhealach níos fearr a fháil ar an fillteán le mír, fág tagairt le do thoil.

<Cód>
ag baint úsáide as Córas;
ag baint úsáide as System.Collections.Generic;
ag baint úsáide as System.Text;
ag baint úsáide as Microsoft.SharePoint;
ag baint úsáide as System.Collections;

ainmspás Conchango
{
    /// <achoimre>
 /// </achoimre>
 ranga ManualFolderUpdate
    {
        statach neamhní Príomh-(teaghrán[] comhbhrí leis an rogha)
        {
            teaghrán MSH = "ManualFolderUpdate (v1.0): "; // msh = "Message Header"

 Consól.WriteLine(MSH + "Starting up.  Bhí mé go deireanach ar an 08/04/08.");

            teaghrán url = http://localhost/xyzzy;

            ag baint úsáide as (SPSite oSPSite = nua SPSite(moladh))
            {

                ag baint úsáide as (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                    SPList docLib = oSPWeb.Lists["Documents"];

                    Consól.WriteLine(MSH + "Got the document library.");

                    Consól.WriteLine(MSH + "Doc lib item count: [" + docLib.ItemCount + "].");

                    int FolderID = 0;
                    teaghrán NewStatus = "xyzzy";

                    FolderID = Chóras.Tiontaigh.ToInt32(comhbhrí leis an rogha[0].ToString());
                    Consól.WriteLine("Seeking folder for item: [" + FolderID + "].");

                    SPListItem li = docLib.GetItemById(FolderID);

                    SPFolder thisItemFolder = li.File.ParentFolder;

                    Consól.WriteLine(MSH + "Got the parent folder.");

                    NewStatus = comhbhrí leis an rogha[1].ToString();
                    Consól.WriteLine("Setting status to [" + NewStatus + "].");

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

                    Consól.ReadLine();

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

                    Consól.WriteLine(MSH + "Finished updating the folder.  Scor.");

                } // ag baint úsáide as SPWeb

            } // ag baint úsáide as SPSite

 Consól.WriteLine(MSH + "Finished.");

        } // Príomh-

    } // rang foldersync
} // ainmspás
</Cód>

</deireadh>

Liostáil le mo bhlag.

Clibeanna Technorati:

Leave a Reply

Ní thabharfar do sheoladh r-phoist a fhoilsiú. Réimsí riachtanacha atá marcáilte *