SharePoint 2007,如何检查文档库中是否存在文件夹 [英] SharePoint 2007, how to check if a folder exists in a document library

查看:33
本文介绍了SharePoint 2007,如何检查文档库中是否存在文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过其 Web 服务访问 SharePoint...这有点受限,因此我转向 WebDav 来执行一些创建文件夹功能...

I am accessing SharePoint via its web services... Which are a bit limited, as a result I have turned to WebDav to perform some create folder functionality...

我有一个文档库,我将要使用 webdav 创建一个文件夹,但是我在 Internet 或其他任何地方都找不到有关如何使用 webdav 检查文件夹是否已存在的任何文档,所以有没有检查 SharePoint 文档库中是否存在文件夹的方法,欢迎使用任何黑客和斜线方法!

I have a document library, and I am about to create a folder using webdav, but I can't find any documentation on the internet or anywhere else on how to check if a folder already exists using webdav, so is there a way to check if a folder exists in a document library in SharePoint, any hack and slash methods welcome!

推荐答案

不知为何,我没明白你的问题.第一句话说明您正在使用 Web 服务(我通常将其理解为 SharePoint 提供的 SOAP Web 服务).下一个说您使用的是 WebDAV,这是一种完全不同的协议.

Somehow, I don't get your question. First sentence states you are using web service (I'd normally understand it as the SOAP web services provided by SharePoint). The next one says you are using WebDAV which is a completely different protocol.

因此,WebDAV 是Windows 资源管理器"用于访问 SharePoint 的协议,如果您将其打开为资源管理器模式".由于所有这些请求实际上都是 HTTP 请求,因此您可以使用 "Fiddler" 工具监视它们.

So, WebDAV is the protocol "Windows Explorer" uses to access SharePoint, if you open it it "Explorer mode". Since all these requests are actually HTTP requests, you can spy on them, using the "Fiddler" tool.

我相信,在打开文件夹之前,Windows 资源管理器会尝试查询共享点,如果此类文件夹存在.如果我尝试打开一个不存在的路径 \mysrvsitesmywebmylib otthere(但 \mysrvsitesmywebmylib 是一个现有的文档库!) 通过 Windows 资源管理器,我看到的最后一个 HTTP 调用是:

I believe, before opening a folder, Windows Explorer tries to query sharepoint, if such folder exists. If I try to open an unexistant path \mysrvsitesmywebmylib otthere (but \mysrvsitesmywebmylib is an existing document library!) thru windows explorer, the last HTTP call I see is:

PROPFIND /sites/myweb/mylib HTTP/1.1
User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7600
Depth: 1
translate: f

SharePoint 响应的地方:此文件夹中的子文件夹和页面列表(很长的 XML,但它包含这样的项目):

Where SharePoint responds with: a list of subfolders and pages in this folder (very long XML, but it contains items like this):

<D:multistatus
    xmlns:D="DAV:"
    xmlns:Office="urn:schemas-microsoft-com:office:office"
    xmlns:Repl="http://schemas.microsoft.com/repl/"
    xmlns:Z="urn:schemas-microsoft-com:">
  <D:response>
    <D:href>http://sites/myweb/mylib</D:href>
    <D:propstat>
      <D:prop>
        <D:displayname>mylib</D:displayname>
        <D:lockdiscovery/>
        <D:supportedlock/>
        <D:isFolder>t</D:isFolder>
        <D:iscollection>1</D:iscollection>
        <D:ishidden>0</D:ishidden>
        <D:getcontenttype>application/octet-stream</D:getcontenttype>
        <D:getcontentlength>0</D:getcontentlength>
        <D:resourcetype>
          <D:collection/>
        </D:resourcetype>
        <Repl:authoritative-directory>t</Repl:authoritative-directory>
        <D:getlastmodified>2009-12-07T09:07:19Z</D:getlastmodified>
        <D:creationdate>2009-11-06T13:30:26Z</D:creationdate>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
  <!---List of other <D:response> elements -->
</D:multistatus>

如果包含的元素是文件夹,则它必须具有D:isFolder"值t".这样您就可以找到父文件夹是否包含您要创建的文件夹.

If the contained element is a folder, it must have "D:isFolder" value "t". This way you can find, if the parent folder contains the folder you are going to create.

创建了一个小的 c# 示例,它首先读取结果流,然后稍微解析结果.你需要把它做得更好,看看列表是否包含你需要的文件夹.

created a small c# sample which first reads the result stream and then parses the result a bit. You need to make it better, to see if the list contains the folders you need or not.

System.Net.HttpWebRequest oReq;
string sUrl = "http://yoursite/sites/somesite/DocumentLibrary";
oReq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(sUrl);

oReq.Method = "PROPFIND";
oReq.Credentials = System.Net.CredentialCache.DefaultCredentials;
oReq.AllowAutoRedirect = true;
oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";

//this causes all of the items to be enumerated, 
//if it is 0, only the folder itself is returned in the response
oReq.Headers["Depth"] = "1";
oReq.Headers["translate"] = "f";
System.IO.StreamWriter oRequest =
        new System.IO.StreamWriter(oReq.GetRequestStream());
oRequest.WriteLine();
oRequest.Close();
System.IO.StreamReader oResponse =
        new System.IO.StreamReader(oReq.GetResponse().GetResponseStream());
string sResponse = oResponse.ReadToEnd();
oResponse.Close();

//done with the webclient stuff, check the results

System.Xml.XmlDocument oMyDoc = new System.Xml.XmlDocument();
oMyDoc.LoadXml(sResponse);
System.Xml.XmlNamespaceManager oNsMgr =
        new System.Xml.XmlNamespaceManager(oMyDoc.NameTable);
oNsMgr.AddNamespace("D", "DAV:");

System.Xml.XmlNodeList oAllResponses =
        oMyDoc.SelectNodes(".//D:multistatus/D:response", oNsMgr);

foreach (System.Xml.XmlNode oNode in oAllResponses)
{
    Console.WriteLine("Name: " + 
                      oNode.SelectSingleNode("./D:propstat/D:prop/D:displayname",
                      oNsMgr).InnerText);

    if (oNode.SelectNodes("./D:propstat/D:prop/D:isFolder", oNsMgr).Count > 0)
    {
        Console.WriteLine("Is folder: " + 
                oNode.SelectSingleNode("./D:propstat/D:prop/D:isFolder", 
                oNsMgr).InnerText);
    }
    else
    {
        Console.WriteLine("Is folder: f");
    }
    Console.WriteLine();
}

这篇关于SharePoint 2007,如何检查文档库中是否存在文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆