开发者

Sharepoint Document library and CAML

开发者 https://www.devze.com 2023-03-20 02:51 出处:网络
I know 开发者_运维知识库folder name I want the ID of that folder which is created in Sharepoint Document Library.

I know 开发者_运维知识库folder name I want the ID of that folder which is created in Sharepoint Document Library. How to write CAML Query to search document library to get folder and its ID Plz help on this..

Rushikesh


SPQuery q = new SPQuery();
q.MeetingInstanceId = -1; //in case your document library is in meeting workspace, query items from all meetings
q.ViewAttributes = "Scope='RecursiveAll'"; //Query all folders (if this is not set, only current folder will be queryied)
q.Query = 



<Where>
      <And>
         <BeginsWith>
            <FieldRef Name='ContentTypeId' />
            <Value Type='Text'>0x0120</Value>
         </BeginsWith>
         <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>Folder name</Value>
         </Eq>
      </And>
   </Where>
  • The ContentTypeId part indicates that we want to query only folders
  • The Title part is where you put in your folder name.

Then you execute query and get the id:

SPListItemCollection items = list.GetItems(q);
if (items.Count > 0)
  int folderId = items[0].ID

You can also enumerate list folders by using SPList.Folders property


I know this is an old thread but I tried the above example in a SP 2010 environment and it didn't work so I thought I'd add my working CAML. Instead of using the ContentTypeID field, I just used ContentType=Folder

<Where>
    <And>
        <Eq>
            <FieldRef Name='ContentType'/>
            <Value Type='Text'>Folder</Value>
        </Eq>
        <Eq>
            <FieldRef Name="Title"/>
            <Value Type='Text'>Folder Name</Value>
        </Eq>
    </And>
</Where>
0

精彩评论

暂无评论...
验证码 换一张
取 消