Office 365中的Sharepoint将文件上传到文档库 [英] Office 365 Sharepoint Upload Files to Documents Library

查看:423
本文介绍了Office 365中的Sharepoint将文件上传到文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用下面的代码使用Web服务将文件添加到我的文档库在SharePoint Office365。

I am trying to use the following code to add files to my document library on Sharepoint Office365 using web services.

public void SaveFileToSharePoint(string fileName)
        {
            try
            {
                var copyService = new Copy { Url = "https://mydomain.com/_vti_bin/copy.asmx", Credentials = new NetworkCredential("username", "password", "domain") };

                var destURL = "https://mydomain.com/Shared%20Documents/" + Path.GetFileName(fileName);

                string[] destinationUrl = { destURL };

                CopyResult[] cResultArray;

                var fFiledInfo = new FieldInformation { DisplayName = "Description", Type = FieldType.Text, Value = Path.GetFileName(fileName) };

                FieldInformation[] fFiledInfoArray = {fFiledInfo};

                var copyresult = copyService.CopyIntoItems(destURL, destinationUrl, fFiledInfoArray, File.ReadAllBytes(fileName), out cResultArray);
                var b = copyresult;
            }
            catch (Exception ex)
            {
            }
        }

我收到对象移动的错误。该URL加载在浏览器中WSDL虽然。如果有更好的方式来上传和Office365从SharePoint获取文件网上我会招待这一点。谢谢你。

I receive the error "Object Moved". The URL loads the WSDL in the browser though. If there is a better way to upload and get files from SharePoint on Office365 online I would entertain that as well. Thanks.

推荐答案

作为Web服务ASMX已被弃用,你应该检查出的SharePoint的新REST服务。 MSDN上找到关于它的信息

as the ASMX webservices are deprecated you should check out the "new" rest services of sharepoint. ON MSDN you find information about it

或者你可以用这将是我最喜欢的方式,客户端对象模型。下面的示例演示基本用法,连接到SharePoint在线查看以下的链接

Or you can use the Client object model which would be my favorite way. The following example shows basic usage, to connect to SharePoint online check out the following link

using(ClientContext context = new ClientContext("http://yourURL"))
{
Web web = context.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(@"C:\myfile.txt");
newFile.Url = "file uploaded via client OM.txt";
List docs = web.Lists.GetByTitle("Documents");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);   
context.ExecuteQuery();
}

这篇关于Office 365中的Sharepoint将文件上传到文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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