Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

REST API Call to Add a Document

$
0
0

Hi All,

I am trying to call the REST API to Add a document to a folder, when I use following URI

https://server.com/MySite/_api/web/GetFolderByServerRelativeUrl('/Documents/Invoices')/Files/add(url='a.pdf',overwrite=false)

I get this error.

System.Net.WebException: The remote server returned an unexpected response: (400) Bad Request.
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="<m:code>-2147024809">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024809, System.ArgumentException</m:code><m:message xml:lang="en-US">Value does not fall within the expected range.</m:message></m:error>

so I looked up online and someone pointed that remove the slash (/) from in front of Documents and that'll resolve the issue, I did that

https://server.com/MySite/_api/web/GetFolderByServerRelativeUrl('Documents/Invoices')/Files/add(url='a.pdf',overwrite=false)

which changed the error to this.

<m:error xmlns:m="<m:code>-2147024893">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024893, System.IO.DirectoryNotFoundException</m:code><m:message xml:lang="en-US">File Not Found.</m:message></m:error>

Not sure, what's wrong, any help greatly appreciated!

Thanks


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>