title: c# update links in excel file in sharepoint through sharepoint client
body: <p>I have a main excel file which has links to several other sub excel files in a sharepoint folder. Let's call the main excel as main.xlsx, and the sub excels as sub1.xlsx, sub2.xlsx.</p>
  
  <p>The first row of each excel is same(header row). The second row of main.xlsx references sub1.xlsx. The 3rd row of main.xlsx references sub2.xlsx, and so on. </p>
  
  <p>The 1st cell of 2nd row in main.xlsx contains the value equal to the content of 1st cell of 2nd row in sub1.xlsx. The 2nd cell of 2nd row in main.xlsx contains the value equal to the content of 2nd cell of 2nd row in sub1.xlsx, and so on.
  Similarly, the cells of 3rd row in main.xlsx are linked to 2nd row of sub2.xlsx.</p>
  
  <p>Please refer to the image to understand the linking between the excels.
  <a href="https://i.stack.imgur.com/piag5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/piag5.jpg" alt="Excels"></a></p>
  
  <p>These all files are in a sharepoint folder. My aim is to download the main.xlsx file to my local server. The excels sub1, sub2 will be modified by respective users. So at the time of download, the main excel should have updated content. This is where I'm facing problem. </p>
  
  <p>I want to update the links in the main excel before it is downloaded. </p>
  
  <p>Below is my code</p>
  
  <pre><code>var clientContext = new ClientContext(url)
  ClientContext context = new ClientContext("https://siteurl");
  context.Credentials = new NetworkCredential("userid", "password", "domain");
  context.Load(context.Web);
  List list = context.Web.Lists.GetByTitle("document library");
  context.Load(list);
  context.ExecuteQuery();
  CamlQuery query = new CamlQuery();
  query.ViewXml = "&lt;view/&gt;";
  ListItemCollection licoll = list.GetItems(query);
  context.Load(licoll);
  context.ExecuteQuery();
  string filePath = @"D:\Docs\sp\";
  foreach(ListItem li in licoll)
  {
      Microsoft.SharePoint.Client.File file = li.File;
      if(file!=null &amp;&amp; file.Name == "main.xlsx")
      {
          var fileRef = file.ServerRelativeUrl;
          FileInformation fileInfo = file.OpenBinaryDirect(context, fileRef.ToString());
  
          var fileName = Path.Combine(filePath,(string)file.Name);
          using (var fileStream = System.IO.File.Create(fileName))
          {                  
              fileInfo.Stream.CopyTo(fileStream);
          }    
      }
  }
  </code></pre>
  
  <p>The code is working fine. Only problem is if someone had updated either sub1 or sub2 excels, the values in main excel are not updated. </p>
  
  <p>I cannot update the links in main excel after downloading as the original files are in sharepoint. 
  So how can I update the links in the main excel before I download it to local machine?</p>
  
  <p>Is it achievable through excelservices or REST API?</p>