C# 将文档从ASP.Net上载到Sharepoint Server
我正在尝试将文件从ASP.Net上载到Sharepoint(为了保留时间戳,我使用这种方式) 下面是我的代码C# 将文档从ASP.Net上载到Sharepoint Server,c#,asp.net,file-upload,httpwebrequest,sharepoint-2013,C#,Asp.net,File Upload,Httpwebrequest,Sharepoint 2013,我正在尝试将文件从ASP.Net上载到Sharepoint(为了保留时间戳,我使用这种方式) 下面是我的代码 protected void UploadFileToSharePoint(string UploadedFilePath, string SharePointPath) { WebResponse response = null; try { string SUrl = "http://Mysha
protected void UploadFileToSharePoint(string UploadedFilePath, string SharePointPath)
{
WebResponse response = null;
try
{
string SUrl = "http://MysharepointPath/Folder";
//WebRequest request = WebRequest.Create(SharePointPath);
WebRequest request = WebRequest.Create(SUrl);
request.Credentials = new NetworkCredential(username,password );
//request.Method = "PUT";
request.Method = "POST";
FileStream fStream = File.OpenRead(UploadedFilePath);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
request.ContentLength = 0;
//Custom code
using (WebClient uploader = new WebClient())
{
try
{
uploader.UploadFile(new Uri(SUrl), UploadedFilePath);
}
catch (Exception ex)
{
}
}
response = request.GetResponse();
}
}
当我尝试在调试模式下运行代码时,它会引发异常
“远程服务器返回错误401未经授权”
“为了保留时间戳,我用这种方式”是什么意思?SharePoint中上载文档的时间戳将是文档添加到SharePoint文档库的日期
错误401(Unauthorized)表示客户端必须首先对自身进行身份验证,因此您是否可以使用Fiddler验证您是否正在SharePoint服务器中进行身份验证
您是使用SharePoint Online还是内部部署
codeplex中有一些示例介绍了您试图实现的功能,请查看此链接以了解更多信息。。。
您的应用程序池标识(应用程序运行的帐户)是否具有对目标文件夹的读/写权限?是的,它具有读/写权限