使用C#将文件上传到SharePoint-(500)内部服务器错误

时间:2018-07-31 09:16:53

标签: c# sharepoint file-upload visual-studio-2015 internal-server-error

我正在尝试在Visual Studio 2015中使用C#将本地文件上传到SharePoint。到目前为止,我已经有了此代码...

string filePath = @"C:\Users\Charlie\Desktop\06062018mix.xlsx";
        string libraryName = "Documents";
        string siteUrl = "http://mysharepointteam/sites/mort_protect/MSP/Test/";
        string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);

        using (ClientContext ctx = new ClientContext(siteUrl))
        {
            ctx.AuthenticationMode = ClientAuthenticationMode.Default;
            FileCreationInformation fcInfo = new FileCreationInformation();
            fcInfo.Url = fileName;
            fcInfo.Overwrite = true;
            fcInfo.Content = System.IO.File.ReadAllBytes(filePath);

            Web myWeb = ctx.Web;
            List myLibrary = myWeb.Lists.GetByTitle(libraryName);
            myLibrary.RootFolder.Files.Add(fcInfo);
            ctx.ExecuteQuery();
        }

但是每次运行它都会出错

  

'Microsoft.SharePoint.Client.dll中发生了'System.Net.WebException类型的未处理异常   附加信息:远程服务器返回错误:(500)内部服务器错误。

我正在使用Microsoft.SharePoint.Client和Microsoft.SharePoint.client.Runtime dll。

任何有关如何克服此错误的建议将不胜感激!

0 个答案:

没有答案
相关问题