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

SharePoint 2013 - Forbidden Access error while trying to update Title property of a file

$
0
0

Hi All,

I am getting Forbidden Access error (403), while trying to update Title property of a file in Sharepoint 2013 using REST API & C#. Code is as below. Can someone correct me where I am going wrong?

string uri ="https://mnp.sharepoint.com/_api/web/getfilebyserverrelativeurl('/Shared Documents/test.txt')"string userName ="abc@mnp.onmicrosoft.com";string password ="abc123";string title ="{'Title': 'Testing'}";byte[] binary =Encoding.UTF8.GetBytes(title);Uri weburi =newUri(uri);var securePassword =newSecureString();foreach(var c in password){ securePassword.AppendChar(c);}var credentials =newSharePointOnlineCredentials(userName, securePassword);var authCookie = credentials.GetAuthenticationCookie(weburi);var cookieContainer =newCookieContainer();
            cookieContainer.SetCookies(weburi, authCookie);string formdigest =this.GetFormDigest(uri, credentials);HttpWebRequest getRequest =(HttpWebRequest)WebRequest.Create(weburi);
            getRequest.Accept="application/json;odata=verbose";
            getRequest.Method="POST";
            getRequest.ContentLength= binary.Length;
            getRequest.CookieContainer= cookieContainer;
            getRequest.Credentials= credentials;
            getRequest.Proxy.Credentials=System.Net.CredentialCache.DefaultCredentials;

            getRequest.Headers.Add("X-RequestDigest", formdigest);Stream st = getRequest.GetRequestStream();
            st.Write(binary,0, binary.Length);HttpWebResponse getResponse =(HttpWebResponse)getRequest.GetResponse();


Ramakrishna


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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