简体   繁体   English

Sharepoint 文档库和 CAML

[英]Sharepoint Document library and CAML

I know folder name I want the ID of that folder which is created in Sharepoint Document Library.我知道文件夹名称我想要在 Sharepoint 文档库中创建的那个文件夹的 ID。 How to write CAML Query to search document library to get folder and its ID Plz help on this..如何编写 CAML 查询来搜索文档库以获取文件夹及其 ID 请对此提供帮助..

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 ContentTypeId 部分表示我们只想查询文件夹
  • The Title part is where you put in your folder name.标题部分是您输入文件夹名称的位置。

Then you execute query and get the id:然后执行查询并获取 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您还可以使用SPList.Folders属性枚举列表文件夹

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.我知道这是一个旧线程,但我在 SP 2010 环境中尝试了上面的示例,但它没有工作,所以我想我会添加我的工作 CAML。 Instead of using the ContentTypeID field, I just used ContentType=Folder我没有使用 ContentTypeID 字段,而是使用了 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM