3

我正在开发一个 Web 应用程序,该应用程序需要获取 SharePoint 上的文件夹和子文件夹,并将其放在表示层次结构的 TreeView 上。我的应用程序与 SharePoint 不在同一台服务器上运行,因此我认为最好的方法是通过 Web 服务。

所以我在我的项目中添加了对 SiteData.asmx 的 Web 引用,并找到了以下代码:

 Private Sub GetSiteData()
    Dim RootFolder As String = "http://mySharepointServer/site/doc_site"
    Dim DirWSSP As String = "http://mySharePointServer/_vti_bin/SiteData.asmx"


    'Definitions of TreeView
    Dim tree As TreeView
    Dim raiz As TreeNode
    Dim no As TreeNode

    tree = Page.FindControl("trvFolder")
    raiz = New TreeNode(RootFolder)
    tree.Nodes.Clear()
    tree.Nodes.Add(raiz)

    ' Definitions of web service
    Dim service As New SP_SiteData.SiteData

    service.Credentials = New System.Net.NetworkCredential("userID", "password", "domain")


    Dim enArray() As SP_SiteData._sFPUrl

    service.EnumerateFolder(RootFolder, enArray)

    Dim en As SP_SiteData._sFPUrl
    For Each en In enArray
        If en.IsFolder Then
            no = New TreeNode(en.Url)
            raiz.ChildNodes.Add(no)
        End If
    Next

End Sub

我从msdn上的一个论坛复制了这段代码,但没有用,service.EnumerateFolder 总是返回一个空数组,也就是说,enArray 总是什么都没有,我得到一个错误:对象引用未设置为对象的实例。

这段代码有效吗?还有另一种方法可以做到这一点吗?我对 Web 服务和 Web 应用程序非常陌生。OBS:我正在使用 Visual Studio 2010 和 SharePoint 2010

4

2 回答 2

1

I found the solution using the web service Lists.asmx.

The problem is I am very novice in web develpment and I don't know nothing about Sharepoint, so i don't knew how to use the web services.

The problem was I was providing the wrong url. The url must be like:

http://mysharepointsite/site/subsite_or_list/_vti_bin/Lists.asmx

and I was using

http://mysharepointsite/_vti_bin/Lists.asmx

The difference is I call the web Service lists.asmx on subsite.

Another thing I didn't know, is that what I was calling the folders are actually lists in sharepoint, so im method getlistitems(), must put the list Name as parameter.

Anyway for futher help, if anybody have the same problem as i had follow this link :

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/99f3e9d0-6ecf-4b1d-8b68-d108f36aaacc

And the code are that here from msd: http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12)

Sorry for the bad english....

Thanks everybody

于 2012-06-22T12:26:41.467 回答
1

ListItems Folders 和 Documents,从 web 服务您可以分辨出与“ows_ContentType”属性的不同。在对象模型中,它们具有 IsFolder 属性。

IEnumerable<XElement> result = from child in root.Descendants(xns + "row")
    where child.Attribute("ows_ContentType").Value == "Folder"
    select child;

此 LINQ 查询可用于 Web 方法结果以仅返回文件夹类型。即使您不了解 LINQ 调用,也很容易看到如何将其更改为适用于“文档”。

*相关注意“GetFolderCollection”的网络服务正在谈论Sharepoint文件夹,它表示网站目录文件夹。

于 2012-07-16T16:01:20.070 回答