确定 SharePoint URL 是否为文件 - MOSS 开箱即用的 Web 服务

发布于 2024-08-01 21:25:34 字数 132 浏览 1 评论 0原文

是否有任何 MOSS 开箱即用的 Web 服务可以获取 SharePoint 网站的 URL 并告诉我们该 URL 是否指向文件(文档)? 例如,我们有一个 SharePoint URL 列表,我们需要找出哪些 URL 指向文件而不是文档库或列表?

Is there any MOSS out of the box web service which takes the URL of a SharePoint site and tells us if that URL is pointing to a file (document)? For example, we have a list of SharePoint URLs and we need to find out which URLs are pointing to a file and not a document library or a list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2024-08-08 21:25:34

我会认真考虑使用 propfind (webdav)。 我无法给您关于如何检查文件或文档库或列表的确切答案,但我可以发布一个函数,该函数可以作为您可能实现的东西的基础......这里是......

/// <summary>
        /// Checks if MOSS resource exists.
        /// </summary>
        /// <param name="url">
        /// The url to the resource.
        /// </param>
        /// <returns>
        /// True or false.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private bool MossResourceExists(string url)
        {
            // Create the web request object
            var oReq = (HttpWebRequest) WebRequest.Create(url);

            // Set the needed properties
            oReq.Method = "PROPFIND";
            oReq.Credentials = wsLists.Credentials; // Use same credentials as wsLists. 
            oReq.AllowAutoRedirect = true;
            oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";

            try
            {
                // Enumerate through top level only, increasing the depth will find children.
                oReq.Headers["Depth"] = "0";
                oReq.Headers["translate"] = "f";
                var oRequest = new StreamWriter(oReq.GetRequestStream());
                oRequest.WriteLine();
                oRequest.Close();
                oReq.GetResponse();
                ////done with the webclient stuff, check the results

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

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

                //foreach (XmlNode oNode in oAllResponses)
                //{
                //    if ()
                //    string oNodeURL = oNode.SelectSingleNode("./D:href", oNsMgr).InnerText.ToLower()
                //    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();
                //}
            }
            catch (WebException ex)
            {
                var errorResponse = ex.Response as HttpWebResponse;

                if (errorResponse != null)
                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return false;
                    }
                    else
                    {
                        throw new Exception("Error checking if URL exists:" + url + ";Status Code:" +
                                            errorResponse.StatusCode + ";Error Message:" + ex.Message);
                    }
            }
            return true;
}

I would seriously consider going with propfind (webdav). I can't give you an exact answer on how to check for file or document library or list, but I can post a function that can serve as a base for something you might implement... here it is....

/// <summary>
        /// Checks if MOSS resource exists.
        /// </summary>
        /// <param name="url">
        /// The url to the resource.
        /// </param>
        /// <returns>
        /// True or false.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private bool MossResourceExists(string url)
        {
            // Create the web request object
            var oReq = (HttpWebRequest) WebRequest.Create(url);

            // Set the needed properties
            oReq.Method = "PROPFIND";
            oReq.Credentials = wsLists.Credentials; // Use same credentials as wsLists. 
            oReq.AllowAutoRedirect = true;
            oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";

            try
            {
                // Enumerate through top level only, increasing the depth will find children.
                oReq.Headers["Depth"] = "0";
                oReq.Headers["translate"] = "f";
                var oRequest = new StreamWriter(oReq.GetRequestStream());
                oRequest.WriteLine();
                oRequest.Close();
                oReq.GetResponse();
                ////done with the webclient stuff, check the results

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

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

                //foreach (XmlNode oNode in oAllResponses)
                //{
                //    if ()
                //    string oNodeURL = oNode.SelectSingleNode("./D:href", oNsMgr).InnerText.ToLower()
                //    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();
                //}
            }
            catch (WebException ex)
            {
                var errorResponse = ex.Response as HttpWebResponse;

                if (errorResponse != null)
                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return false;
                    }
                    else
                    {
                        throw new Exception("Error checking if URL exists:" + url + ";Status Code:" +
                                            errorResponse.StatusCode + ";Error Message:" + ex.Message);
                    }
            }
            return true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文