1
votes

How can one resolve this runtime error?

Error

Could not load file or assembly 'Microsoft.SharePoint.Library, Version = 14.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c' or one of its dependencies. The system can not find the file specified.

CODE

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();
}
4
what're you using? SharePoint client object model SDK? - Matt
No, Just a Simple Windows Form Aplication Project - Nevesito
Then how do your program connect to SharePoint online? - Matt

4 Answers

3
votes

This works for me.

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();
}
1
votes
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();
}
-1
votes

You cannot use the server side object model to upload files to SharePoint Online.

One has to use the Client Object Model to upload files to SharePoint online.

More Info

Office 365 Sharepoint Upload Files to Documents Library

-1
votes

Have you encountered this error: The partner returned a bad sign-in name or password error. For more information, see Federation Error-handling Scenarios.

I have the following codes:

                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);