REST API in c# to upload document in document Library of sharepoint
in auto hosted app,is possible upload documents sharepoint document library of rest in c#. dont know whether rest can used in c# or not. please let me know.
regards,
chaitanya
c# , rest can go together. example:
using (var clientcontext = tokenhelper.getclientcontextwithaccesstoken(sharepointurl.tostring(), apponlyaccesstoken)) { byte[] bytefile = system.io.file.readallbytes(pathtofile); httpwebrequest endpointrequest = (httpwebrequest)httpwebrequest.create(hostweb + "/_api/web/getfolderbyserverrelativeurl('shared%20documents')/files/add(url='filename.txt',overwrite=true)"); endpointrequest.method = "post"; endpointrequest.headers.add("binarystringrequestbody", "true"); endpointrequest.headers.add("authorization", "bearer " + apponlyaccesstoken); endpointrequest.getrequeststream().write(bytefile, 0, bytefile.length); httpwebresponse endpointresponse = (httpwebresponse)endpointrequest.getresponse(); }
please mark reply helpful (the arrow) if useful , please mark answer (the check box) if answered question! thank you!
danny jessee | mcpd - sharepoint developer 2010 | mcts - sharepoint 2010, configuring
blog: http://dannyjessee.com/blog | twitter: @dannyjessee
SharePoint , Apps for Office and SharePoint > Developing Apps for SharePoint 2013
Comments
Post a Comment