I am currently trying to write an application using C# that accesses a file stored on a SharePoint server programatically using the REST API. For that purpose, I want to check out a file. The file exists at this path:
http://myserver.mydomain.com/sites/MyCompany/012_MyDepartment/Shared%20Documents/rm/MyToolConfig/config.xml
When I paste this line in my browser, I see the file.
Next thing I do is to use REST like this:
http://myserver.mydomain.com/_api/web/GetFileByServerRelativeUrl('/sites/MyCompany/012_MyDepartment/Shared%20Documents/rm/MyToolConfig/config.xml')/CheckOut()
According to the REST-documentation, this should work. However, when I paste this path to my browser, I get the following error:
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2146232832, Microsoft.SharePoint.SPException</m:code>
<m:message xml:lang="en-US">
The file /sites/MyCompany/012_MyDepartment/Shared%20Documents/rm/MyToolConfig/config.xml does not exist.
</m:message>
</m:error>
So the question is: is it possible that the server maps the physical path of the file internally to another location? How can I figure out what the correct path is that needs to be passed to the function "GetFileByServerRelativeUrl"
?
Please note that I do not administrate that SharePoint server, I only have to use it as a "black box" to store and get files from.
EDIT: Here is some sample code I currently use:
const string serverName = @"http://myserver.mydomain.com/sites/MyCompany/_api/web/GetFileByServerRelativeUrl('/sites/MyCompany/012_MyDepartment/Shared%20Documents/rm/MyToolConfig/config.xml')/CheckOut()";
HttpWebRequest req = WebRequest.Create(serverName) as HttpWebRequest;
req.Method = "POST";
req.Credentials = CredentialCache.DefaultCredentials;
req.Headers.Add("X-RequestDigest", GetFormDigest());
req.ContentLength = 0;
HttpWebResponse myWebResponse = (HttpWebResponse)req.GetResponse();
/_api/web/lists/getbytitle('Shared Documents')/items
. Find the list item pertaining to your document, and it should tell you the REST request for it's file.