【问题标题】:Upload File To SharePoint Online(office 365) Library Invokes Error将文件上传到 SharePoint Online(office 365) 库调用错误
【发布时间】:2014-07-01 11:54:38
【问题描述】:

如何解决这个运行时错误?

错误

无法加载文件或程序集“Microsoft.SharePoint.Library,版本 = 14.0.0.0,文化 = 中性,PublicKeyToken = 71e9bce111e9429c”或其依赖项之一。系统找不到指定的文件。

代码

string destUrl = "URL";
string destFileUrl = destUrl  + "biblioteca" + "/text.txt";
using(SPWeb site = new SPSite(destUrl).OpenWeb())
{
    site.AllowUnsafeUpdates = true;

    FileStream fileStream = File.Open("FILE" , FileMode.Open);

    site.Files.Add(destFileUrl, fileStream, true/*overwrite*/);

    fileStream.Close();
}

【问题讨论】:

  • 你在用什么? SharePoint 客户端对象模型 SDK?
  • 不,只是一个简单的 Windows 窗体应用项目
  • 那么你的程序是如何连接到在线SharePoint的呢?

标签: c# sharepoint office365


【解决方案1】:

这对我有用。

using (ClientContext clientContext = new ClientContext("SHAREPOINT URL")) {
    SecureString passWord = new SecureString();
    foreach (char c in "PASSWORD".ToCharArray()) passWord.AppendChar(c);
    clientContext.Credentials = new SharePointOnlineCredentials("ACOUNT.onmicrosoft.com", passWord);
    Web web = clientContext.Web; 
    FileCreationInformation newFile = new FileCreationInformation();
    newFile.Content = System.IO.File.ReadAllBytes(FILE);
    newFile.Url = NAMEFORTHEFILE;
    
    List docs = web.Lists.GetByTitle("LIBRARY NAME");
    Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);

    clientContext.ExecuteQuery();
}

【讨论】:

    【解决方案2】:
    string fileName = @"C:\AddUser.aspx";
    using (var context = new   ClientContext("https://yourdomain.com")) {
        var passWord = new SecureString();
        foreach (var c in "YourPassword") passWord.AppendChar(c);
        context.Credentials = new SharePointOnlineCredentials("YourUsername", passWord);
        var web = context.Web;
        var newFile = new FileCreationInformation {
            Content = System.IO.File.ReadAllBytes(fileName),
            Url = Path.GetFileName(fileName)
        };
        var docs = web.Lists.GetByTitle("Pages");
        Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
        context.ExecuteQuery();
    }
    

    【讨论】:

      【解决方案3】:

      您是否遇到过此错误:合作伙伴返回了错误的登录名或密码错误。有关详细信息,请参阅联合错误处理方案。

      我有以下代码:

                      NetworkCredential Cred = new NetworkCredential(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"], ConfigurationManager.AppSettings["Domain"]);
                      SecureString PassWord = new SecureString();
      
                      foreach (char c in ConfigurationManager.AppSettings["Password"].ToCharArray()) PassWord.AppendChar(c);
      
                      clientContext.Credentials = new SharePointOnlineCredentials(ConfigurationManager.AppSettings["Username"], PassWord);
      
                      Web web = clientContext.Web;
      
                      clientContext.Load(web);
      

      【讨论】:

        【解决方案4】:

        不能使用服务器端对象模型将文件上传到 SharePoint Online。

        必须使用客户端对象模型将文件上传到在线 SharePoint。

        更多信息

        Office 365 Sharepoint Upload Files to Documents Library

        【讨论】:

        • 我已尝试使用您发布的链接中提供的代码!我可以在 Windows 窗体应用程序中使用它吗?
        • 是的,您可以在 Windows 应用程序中使用此代码。您需要添加对以下 dll 的引用:Microsoft.SharePoint.Client.dll Microsoft.SharePoint.Client.Silverlight.Runtime.dll
        • Microsoft.SharePoint.Client.Silverlight.Runtime.dll 我没有 thsi dll 只有 icrosoft.SharePoint.Client.Runtime.dll
        • 在这种情况下可以。你不需要 Microsoft.SharePoint.Client.Silverlight.Runtime.dll
        猜你喜欢
        • 2013-10-08
        • 2013-06-03
        • 2019-01-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-04
        • 1970-01-01
        • 2021-09-25
        相关资源
        最近更新 更多