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
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
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
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.
Commented
Sep 29, 2015 at 16:30