2

Using REST API, is there a way we can upload a file to SharePoint and also create the folder to which file to be uploaded. Say for example here “/testfolder” does not exist already in SharePoint and we need to create the folder at the time of uploading the file.

https://mysite.sharepoint.com/sites/sitename/_api/web/GetFolderByServerRelativeUrl(@folderurl)/Files/add(url=@filename)?@folderurl='/sites/sitename/foldername/testfolder'&@filename='sn_test_01.txt'

Thank you.

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

I don't think this is possible via REST API....Infact it is one of limitation that for doing some simple things you need to make multiple calls in REST API.

To create folder you need to make below call

url: http://site url/_api/web/folders
method: POST
body: { '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/document library relative url/folder name'}
Headers: 
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
    content-length:length of post body

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.