nec*_*666 5 sharepoint sharepoint-2013
我有一个问题能够得到一个文件夹中的项目列表,它不断给我的列表文件夹在图书馆,而不是文件列表中指定的文件夹。
我正在使用 C# 程序,使用以下方法调用 Web 服务 GetListItems,并且这一切似乎都可以正常工作:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetListItems", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Xml.XmlNode GetListItems(string listName, string viewName, System.Xml.XmlNode query, System.Xml.XmlNode viewFields, string rowLimit, System.Xml.XmlNode queryOptions, string webID) {
object[] results = this.Invoke("GetListItems", new object[] {
listName,
viewName,
query,
viewFields,
rowLimit,
queryOptions,
webID});
return ((System.Xml.XmlNode)(results[0]));
}
Run Code Online (Sandbox Code Playgroud)
参数值如下:
listName = "Letters"
viewName = null
query = null
viewFields.OuterXml = "<ViewFields>
<FieldRef Name=\"ID\" />
<FieldRef Name=\"Title\" />
<FieldRef Name=\"Modified\" />
<FieldRef Name=\"Status\" />
<FieldRef Name=\"_UIVersion\" />
<FieldRef Name=\"_UIVersionString\" />
<FieldRef Name=\"EpisodeId\" />
</ViewFields>"
rowLimit = null
queryOptions.OuterXml = "<QueryOptions>
<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>
<Folder>http://D3TVCAPP-APP02.test.local/Letters/ABBOTT, Nash _489611</Folder>
<DateInUtc>TRUE</DateInUtc>
</QueryOptions>"
webID = null
Run Code Online (Sandbox Code Playgroud)
它实际上返回了一个结果,它正在击中服务,结果如下所示:
results.OuterXml =
"<listitems xmlns:s=\"uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882\" xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\" xmlns:rs=\"urn:schemas-microsoft-com:rowset\" xmlns:z=\"#RowsetSchema\" xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<rs:data ItemCount=\"2\">
<z:row
ows_ID=\"84\"
ows_Modified=\"2021-06-09T09:50:11Z\"
ows__UIVersion=\"1\"
ows__UIVersionString=\"0.1\"
ows__ModerationStatus=\"2\"
ows__Level=\"2\"
ows_UniqueId=\"84;#{C8E8EC38-6DD5-4275-873A-B829BA850A54}\"
ows_owshiddenversion=\"1\"
ows_FSObjType=\"84;#1\"
ows_Created_x0020_Date=\"84;#2021-06-09T09:50:11Z\"
ows_ProgId=\"84;#\"
ows_FileLeafRef=\"84;#ABBOTT, Nash _489611\"
ows_PermMask=\"0x7fffffffffffffff\"
ows_FileRef=\"84;#Letters/ABBOTT, Nash _489611\"
ows_Editor=\"1;#John Smith\"
ows_MetaInfo=\"84;#\"
ows_Last_x0020_Modified=\"84;#2021-06-09T09:50:14Z\"
/>
<z:row
ows_ID=\"3\"
ows_Modified=\"2020-11-04T13:02:42Z\"
ows__UIVersion=\"1\"
ows__UIVersionString=\"0.1\"
ows__ModerationStatus=\"2\"
ows__Level=\"2\"
ows_UniqueId=\"3;#{1CA7B690-BF90-41EC-A5EA-E910C8D72376}\"
ows_owshiddenversion=\"1\"
ows_FSObjType=\"3;#1\"
ows_Created_x0020_Date=\"3;#2020-11-04T13:02:42Z\"
ows_ProgId=\"3;#\"
ows_FileLeafRef=\"3;#SMITH, JOHN _483835\"
ows_PermMask=\"0x7fffffffffffffff\"
ows_FileRef=\"3;#Letters/SMITH, JOHN _483835\"
ows_Editor=\"1;#John Smith\"
ows_MetaInfo=\"3;#\"
ows_Last_x0020_Modified=\"3;#2020-11-06T16:59:03Z\"
/>
</rs:data>
</listitems>"
Run Code Online (Sandbox Code Playgroud)
为代码墙道歉,我只是希望有人可以帮助我并希望提供尽可能多的信息。我无法弄清楚这一点,我觉得我做的一切都是正确的。任何人都知道我做错了什么?
C# 编程为开发人员提供了两种使用 SharePoint 数据的选项:看到您的代码,我认为您尝试使用REST API 方法使用 SharePoint 数据。REST API 方法通常用于与 SharePoint 和由其他编程语言(与 C# 不同)编写的外部系统建立接口,并且 C# 开发人员社区使用频率不高;但是,需要明确的是:这不是规则,也不是不可能使用 C# 中的 REST API 来使用 SharePoint 数据,但这与CSOM 方法相比更加“困难”相比更加“困难” 。
\n现在,我将向您展示一个使用CSOM 方法的示例从特定文件夹获取文件的示例,您将得到结论:
\nMicrosoft.SharePoint.Client.dll和Microsoft.SharePoint.Client.Runtime.dll;\n\n
using System;\nusing System.Net;\nusing System.Security;\nusing System.Collections.Generic;\nusing Microsoft.SharePoint.Client;\n\nnamespace SharePoint.Csom.Approach\n{\n public class SharePointDocumentModel\n {\n public string FileName { get; set; }\n\n public string Url { get; set; }\n\n public string Version { get; set; }\n }\n\n public class SharePointDocuments : IDisposable\n {\n private bool _disposed = false;\n\n protected readonly ClientContext _clientContext;\n\n public SharePointDocuments(string sharepointSiteUrl, string user, SecureString password)\n {\n if (string.IsNullOrWhiteSpace(sharepointSiteUrl) || !sharepointSiteUrl.StartsWith("http"))\n {\n throw new InvalidOperationException("Impossible to connect with invalid URL.");\n }\n this._clientContext = new ClientContext(sharepointSiteUrl);\n this._clientContext.AuthenticationMode = ClientAuthenticationMode.Default;\n this._clientContext.Credentials = new NetworkCredential(user, password);\n }\n\n public IEnumerable<SharePointDocumentModel> GetFiles(string folderRelativeURL)\n {\n Web web = this._clientContext.Web;\n this._clientContext.Load(web);\n this._clientContext.ExecuteQuery();\n Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + folderRelativeURL);\n this._clientContext.Load(folder);\n this._clientContext.ExecuteQuery();\n FileCollection fileCol = folder.Files;\n this._clientContext.Load(fileCol);\n this._clientContext.ExecuteQuery();\n foreach (File file in fileCol)\n {\n string fileVersion = null;\n FileVersionCollection oFileVersionCollection = file.Versions;\n this._clientContext.Load(oFileVersionCollection);\n this._clientContext.ExecuteQuery();\n foreach (FileVersion oFileVersion in oFileVersionCollection)\n {\n fileVersion = oFileVersion.VersionLabel;\n }\n yield return new SharePointDocumentModel()\n {\n FileName = file.Name,\n Url = file.ServerRelativeUrl,\n Version = fileVersion\n };\n }\n }\n\n public void Dispose()\n {\n this.Dispose(true);\n }\n\n private void Dispose(bool disposing)\n {\n if (this._disposed)\n {\n return;\n }\n if (disposing)\n {\n if (null != this._clientContext)\n {\n this._clientContext.Dispose();\n }\n }\n this._disposed = true;\n }\n\n ~SharePointDocuments()\n {\n this.Dispose(false);\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n
\n\n
List<SharePoint.Csom.Approach.SharePointDocumentModel> files = new List<SharePoint.Csom.Approach.SharePointDocumentModel();\nusing (SharePoint.Csom.Approach.SharePointDocuments sharepoint = new SharePoint.Csom.Approach.SharePointDocuments("http://D3TVCAPP-APP02.test.local", "user", "password"))\n{\n files = sharepoint.GetFiles("/Letters/ABBOTT, Nash _489611").ToList();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n
进行测试后,请向我们提供反馈。
\n谢谢。
\n| 归档时间: |
|
| 查看次数: |
86 次 |
| 最近记录: |