嗨,我有以下代码将文件上传到Sharepoint.它使用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; } }
当我运行此代码时,我得到异常:
"远程服务器返回错误:(409)冲突."
有没有人对我出错的地方有任何想法?
谢谢,
亚历克斯
当我引用文档库的url而不是目标文件本身时,我遇到了这个问题.
即尝试http://服务器名称/文档库名称/新文件名.doc