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

400 Bad Request Updating File Properties Through REST Api

$
0
0

I am attempting to upload a file to Sharepoint 2013 and then update its file properties.  I am able to upload the file with no problem, but once I attempt to update the file properties I get a 400 Bad Request error.  My code is below

string spUri = string.Format("https://clients.xxxxxxxxxxx.com/{0}/_api/web/getFileByServerRelativeUrl('{1}')/ListItemAllFields", SubSite, fileId);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(spUri);
            request.Method = "POST";
            request.Credentials = new NetworkCredential("svcSharePoint", "**********");
            request.PreAuthenticate = true;
            request.Accept = "application/json;odata=verbose";
            request.ContentType = "application/json;odata=verbose";
            request.Headers.Add("X-RequestDigest", digestToken);
            request.Headers.Add("X-Http-Method", "MERGE");
            request.Headers.Add("IF-MATCH", "*");

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                string json = "{\"__metadata\": { type: \"SP.Data.Project_x0020_DocumentsItem\" }, \"Modified_x0020_By\": \"i:0#.w|" + User + "\", \"Created_x0020_By\": \"i:0#.w|" + User + "\", \"ActiveDocsURL\": \"https://webplans.responsegroupinc.com/activedocs\", \"ActiveDocsDocID\": \"" +
                    ADGuid + "\", \"ActiveDocsStatus\": \"" + ADStatus + "\"}";

                streamWriter.Write(json);
                streamWriter.Flush();
            }

            WebResponse response = request.GetResponse();
            Stream data = response.GetResponseStream();
            StreamReader reader = new StreamReader(data, Encoding.UTF8);
            string responseString = reader.ReadToEnd();
            response.Close();


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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