You must Sign In to post a response.
  • Category: Sharepoint

    How to Update sitecoloumns in SP 2013

    Are you looking for a way to Update sitecoloumns in SP 2013 ? then read this thread to know how to add it

    Below Code - Adds file to sharepoint 2013 document library, from here i also want to update Site Columns related
    to it like Id,TypeID, Type etc ... can somebody guide over this

    //Create a namespace manager for parsing the ATOM XML returned by the queries.
    XmlNamespaceManager xmlnspm = new XmlNamespaceManager(new NameTable());

    //Add pertinent namespace to the namespace manager.
    xmlnspm.AddNamespace("d", "");

    //Execute a REST request to get the form digest. All POST requests that change the
    //state of resources on the host
    //Web require the form digest in the request header.

    HttpWebRequest contextinfoRequest =
    (HttpWebRequest)HttpWebRequest.Create("http://testserver:10050/" + "/_api/contextinfo");
    contextinfoRequest.Method = "POST";
    contextinfoRequest.ContentType = "text/xml;charset=utf-8";
    contextinfoRequest.ContentLength = 0;
    contextinfoRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

    HttpWebResponse contextinfoResponse = (HttpWebResponse)contextinfoRequest.GetResponse();
    StreamReader contextinfoReader = new StreamReader(contextinfoResponse.GetResponseStream(), System.Text.Encoding.UTF8);
    var formDigestXML = new XmlDocument();
    var formDigestNode = formDigestXML.SelectSingleNode("//d:FormDigestValue", xmlnspm);
    string formDigest = formDigestNode.InnerXml;

    string srcUrl = @"D:\VisCore\VS.VisCore.Website\Images\Viscore_Status.docx";

    string srcUrl1 = "Viscore_Status.docx";

    HttpWebRequest endpointRequest3 = (HttpWebRequest)HttpWebRequest.Create("http://testserver:10050/_api/web/GetFolderByServerRelativeUrl('/VisCore/BSDocs/Documents/1754/')/Files/add(url='" + srcUrl1 + "',overwrite=true)");

    endpointRequest3.Credentials = System.Net.CredentialCache.DefaultCredentials;

    if (!File.Exists(srcUrl))
    throw new ArgumentException(String.Format("{0} does not exist",
    srcUrl), "srcUrl");

    FileStream fStream = File.OpenRead(srcUrl);
    string fileName = fStream.Name.Substring(3);
    byte[] contents = new byte[fStream.Length];
    fStream.Read(contents, 0, (int)fStream.Length);

    endpointRequest3.ContentLength = contents.Length;
    endpointRequest3.Headers.Add("X-RequestDigest", formDigest);

    Stream listRequestStream = endpointRequest3.GetRequestStream();
    listRequestStream.Write(contents, 0, contents.Length);
    HttpWebResponse listResponse = (HttpWebResponse)endpointRequest3.GetResponse();
    catch (WebException e)
    using (WebResponse response = e.Response)
    HttpWebResponse httpResponse = (HttpWebResponse)response;
    Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
    using (Stream data = response.GetResponseStream())
    using (var reader = new StreamReader(data))
    string text = reader.ReadToEnd();
  • #750421
    Hello anbu,

    Is there any issue regarding this snippet?
    If you want to just post snippet or an article than you should post it on article setion.

    If you have some issue regarding that than update your question with more details regarding error,
    You will get more responses after that.

    Nirav Prabtani (Senior Web Developer)
    Email :
    blog :

  • #750423
    Hi anbu,

    I don't know what type of issue are you facing on here, but In SharePoint if you try to update the columns it won't accept, why because while creating column itself internally it will create Id for that particular column when you update the column it's update in outer surface but internally it will fetch that particular id only. So, if you want to move the particular column information into another then simply create one more column and move the col1 information into col2 then delete col1 that is only the way to do this.

    If you are looking for something different then please revert back.

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments