使用webservices将文档上载到Sharepoint 2013 Online

我有一个客户在Sharepoint 2013 Online中实现客户门户。 当前程序通过邮件将文档分发给客户。 现在我们必须将文档上传到客户门户。

我尝试在sharepoint中使用copy webservice。 我创建了一个测试项目并将webservice添加为Web Reference并编写了以下测试代码:

static void Main(string[] args) { string baseUrl = "https://mycustomer.sharepoint.com/sites/"; string customer = "customerportalname"; string serviceUrl = "/_vti_bin/copy.asmx"; string destinationDirectory = "/folder/"; string fileName = "uploaded.xml"; string username = "username@outlook.com"; string password = "password"; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml("voorwielachterwieltrappersstuurframe"); byte[] xmlByteArray; using (MemoryStream memoryStream = new MemoryStream()) { xmlDocument.Save(memoryStream); xmlByteArray = memoryStream.ToArray(); } string destinationUrl = string.Format("{0}{1}{2}{3}", baseUrl, customer, destinationDirectory, fileName); string[] destinationUrlArray = new string[] { destinationUrl }; FieldInformation fieldInfo = new FieldInformation(); FieldInformation[] fields = { fieldInfo }; CopyResult[] resultsArray; using (Copy copyService = new Copy()) { copyService.PreAuthenticate = true; copyService.Credentials = new NetworkCredential(username, password); copyService.Url = string.Format("{0}{1}", baseUrl, serviceUrl); copyService.Timeout = 600000; uint documentId = copyService.CopyIntoItems(destinationUrl , destinationUrlArray, fields, xmlByteArray, out resultsArray); } } 

当我执行代码时,我收到以下错误:

 The request failed with the error message: -- Object moved 

Object moved to here.

--

看起来我没有经过身份validation并被重定向。 但凭证是正确的。 有没有人有想法? 提前致谢!

UPDATE

若要连接到SharePoint 2013 Online,您必须附加Office 365身份validationCookie,如本文所述。 然而,我的问题是还涉及到ADFS。 我如何validationADFS?

由于validation模式不正确,最有可能发生此错误。
由于SharePoint Online(SPO)使用基于声明的身份validation ,因此无法在SPO中使用NetworkCredential Class进行身份validation。 为了在SPO中对ADFS执行身份validation,您可以使用SharePoint Online Client Components SDK中的 SharePointOnlineCredentials类 。

如何在SharePoint Online(SPO)中validationSharePoint Web服务

以下示例演示了如何检索身份validationCookie:

 private static CookieContainer GetAuthCookies(Uri webUri, string userName, string password) { var securePassword = new SecureString(); foreach (var c in password) { securePassword.AppendChar(c); } var credentials = new SharePointOnlineCredentials(userName, securePassword); var authCookie = credentials.GetAuthenticationCookie(webUri); var cookieContainer = new CookieContainer(); cookieContainer.SetCookies(webUri, authCookie); return cookieContainer; } 

 string sourceUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide.docx"; string destinationUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide 2013.docx"; FieldInformation[] fieldInfos; CopyResult[] result; byte[] fileContent; using(var proxyCopy = new Copy()) { proxyCopy.Url = webUri + "/_vti_bin/Copy.asmx"; proxyCopy.CookieContainer = GetAuthCookies(webUri, userName, password); proxyCopy.GetItem(sourceUrl,out fieldInfos,out fileContent); proxyCopy.CopyIntoItems(sourceUrl,new []{ destinationUrl}, fieldInfos, fileContent, out result); } 

参考

  • SharePoint Online中的远程身份validation使用基于声明的身份validation
  • SharePoint Online Client组件SDK

在我的情况下(内部)我有这个错误。 当我更改为Web应用程序的iis SharePoint身份validation时,并禁用“表单身份validation”。 现在,我无法通过UI进入SharePoint,但Web服务正常工作…所以我已经恢复,我一直在寻找……

[Paul stork]此站点的Web应用程序以经典模式而非声明模式运行。 如果您使用Powershell创建Web应用程序或从2010年升级,则会发生这种情况。您可以使用PowerShell进行更改。

http://technet.microsoft.com/en-us/library/gg251985.aspx

我已经在管理中心(在同一个服务器场中)由UI创建的另一个新应用程序中尝试了Web服务,并且它已经运行了。 问题是Web应用程序。

尝试: http : //sharepointyankee.com/2011/01/04/the-request-failed-with-the-error-message-object-moved-sharepoint-2010-web-services-fba/扩展您的混合身份validation网络应用程序,并为Windows身份validation创建一个区域,然后更改Web服务属性中的Web引用URL,以使用该扩展的URL和端口。 你应该没有这种问题了。