我正在尝试使用以下代码通过 Web 服务将文件添加到 Sharepoint Office365 上的文档库。
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 Online 上从 SharePoint 上传和获取文件,我也会考虑的。谢谢。
由于 ASMX Web 服务已弃用,您应该查看 sharepoint 的“新”其余服务。在 MSDN 上您可以找到有关它的信息 http://msdn.microsoft.com/en-us/library/office/apps/jj164022.aspx
或者您可以使用客户端对象模型,这将是我最喜欢的方式。以下示例显示了基本用法,要连接到 SharePoint Online,请查看以下内容
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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)