1

currently created Picture Library using csom

on host Web in my last question, now trying to add some Images to that Library, So for that created Image folder into SharePoint Hosted App. how to achive above task

1
  • Just a heads up: the API you're looking to use is (or was at one point) called JSOM. (JavaScript SharePoint Object Model) CSOM (Client SharePoint Object Model) is currently only implemented for .NET languages. Both are based on the SharePoint Client Query Protocol, but since each implementation comes with its own limitations, you might find more relevant information using the proper term. Sep 29 '15 at 16:25
3

You can upload images using File.SaveBinaryDirect Method in sharepoint.

Go through MSDN, Also work in SharePoint Online.

Example

using (var clientContext = new ClientContext(url))
{
 using (var fs = new FileStream(fileName, FileMode.Open))
 {
     var fi = new FileInfo(fileName);
     var list = clientContext.Web.Lists.GetByTitle(listTitle);
     clientContext.Load(list.RootFolder);
     clientContext.ExecuteQuery();
     var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);

     Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
 }
}

Note: NetworkCredential is used in on-premises environment, SharePointOnlineCredentials in SharePoint Online

5
  • If you get answer please mark as Answer..!! Jul 9 '15 at 9:36
  • m trying to use JavaScrip (CSOM) If not Possible Using Java Scrip then give some suggesions Jul 9 '15 at 11:39
  • Okey.. Let me know if not done through javascript.. Jul 9 '15 at 12:22
  • after some research found that not possible to upload images in library using java script , can i use REST API for that? Jul 9 '15 at 12:24
  • Unless it's changed since the last time I checked, SaveBinaryDirect uses SharePoint's WebDAV endpoint to upload files. To use it yourself, you'd need to direct a PUT HTTP request with the request body containing your uploaded image. Not sure that really helps in your case, but if you'd like me to post an answer with more info, let me know. Sep 29 '15 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.