.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Upload files to document library SharePoint Online.

Posted By:abhays       Posted Date: August 31, 2014    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Upload files to document library SharePoint Online.

Upload files to document library SharePoint Online.
string Url = "http://SiteUrl";
string libraryName = "MyDocs";
string fileName = "c:\\Test.txt";
using (ClientContext clientContext = new ClientContext(Url))
    SecureString passWord = new SecureString();
    foreach (char c in "Password".ToCharArray()) passWord.AppendChar(c);
    clientContext.Credentials = new SharePointOnlineCredentials("sampleuser@domain.onmicrosoft.com", passWord);
    List list = clientContext.Web.Lists.GetByTitle(libName);
    using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
        Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, list.RootFolder.ServerRelativeUrl.ToString() + "/" +         fileName.Split('\\')[1], fileStream, true);


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend