使用 HTTP PUT 将文件上传到 Sharepoint (WSS 3.0) 文档库 [英] Uploading files to Sharepoint (WSS 3.0) document library using HTTP PUT
本文介绍了使用 HTTP PUT 将文件上传到 Sharepoint (WSS 3.0) 文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有以下代码可以将文件上传到 Sharepoint.它使用 HTTP PUT:
Hi I have the following piece of code to upload a file to Sharepoint. It uses HTTP PUT:
public static string UploadFile(string destUrl, string sourcePath)
{
try
{
Uri destUri = new Uri(destUrl);
FileStream inStream = File.OpenRead(sourcePath);
WebRequest req = WebRequest.Create(destUri);
req.Method = "PUT";
req.Headers.Add("Overwrite", "F");
req.Timeout = System.Threading.Timeout.Infinite;
req.Credentials = CredentialCache.DefaultCredentials;
Stream outStream = req.GetRequestStream();
string status = CopyStream(inStream, outStream);
if (status == "success")
{
outStream.Close();
WebResponse ores = req.GetResponse();
return "success";
}
else
{
return status;
}
}
catch (WebException we)
{
return we.Message;
}
catch (System.Exception ee)
{
return ee.Message;
}
}
当我运行此代码时,出现异常:
When I run this code I get the exception:
远程服务器返回错误:(409) 冲突."
"The remote server returned an error: (409) Conflict."
有没有人知道我哪里出错了?
Does anyone have any ideas as to where I am going wrong?
谢谢,
亚历克斯
推荐答案
当我引用文档库的 url 而不是目标文件本身时,我遇到了这个问题.
I've had this issue when I was referencing the url of the document library and not the destination file itself.
即试试 http://server 名称/文档库名称/新文件名.doc
i.e. try http://server name/document library name/new file name.doc
这篇关于使用 HTTP PUT 将文件上传到 Sharepoint (WSS 3.0) 文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文