title: Update the "Created By" of a Sharepoint Document Library column via ClientContext
body: <p>I wanted to updated the Created By column in SharePoint via client context, but my code is not working. The column is a document library column.</p>
  
  <p>I tried a few options. My first code block fails to update the field, but my second code block actually does the trick, but it couldn't manage to upload files bigger than 150&nbsp;MB which my first code block is able to do.</p>
  
  <p><strong>Here is my first code block:</strong></p>
  
  <pre><code>using (var ctx = new ClientContext(spSiteUrl))
  {
      ctx.RequestTimeout = 1000000;
      Web web = ctx.Web;
  
      string strUser = "spDomain\\adminUser1";
  
      var file = ctx.Web.GetFileByServerRelativeUrl(newServerRelPath);
      var item = file.ListItemAllFields;
  
      //First approach and it doesn't work
      // -&gt; Start
      FieldUserValue fuvUser = new FieldUserValue();
      User oUser = web.EnsureUser(strUser);
      ctx.Load(oUser,
      props=&gt;props.Id,
      props=&gt;props.LoginName);
      item["Author"] = oUser;
      item["Created_x0020_By"] = oUser;
      // -&gt; End
  
      //Second approach and still it doesn't work
      // -&gt; Start
      List list = web.GetList(spDocLibUrl);
      list.Fields.GetByInternalNameOrTitle("Author").ReadOnlyField = false;
      list.Fields.GetByInternalNameOrTitle("Created_x0020_By").ReadOnlyField = false;
      list.Update();
      item["Author"]=web.EnsureUser(strUser);
      item["Created_x0020_By"] = web.EnsureUser(strUser);
      // -&gt; End
  
      item.Update();
      ctx.ExecuteQuery();
  
  }
  </code></pre>
  
  <p><strong><em>How do I update the Created By field</em></strong>?</p>
  
  <p>Another approach I did on my code can actually update the Created By field, but my problem here is that I can't upload files bigger that 150&nbsp;MB.</p>
  
  <p><strong>Here is my second code block:</strong></p>
  
  <pre><code>SPSecurity.RunWithElevatedPrivileges(delegate()
  {
      using (SPSite site = new SPSite(spSiteUrl))
      {
          using (SPWeb web = site.OpenWeb())
          {
              //read file in filestream
              System.IO.FileStream fStream = System.IO.File.OpenRead(filePath);
              byte[] contents = new byte[fStream.Length];
              fStream.Read(contents, 0, (int)fStream.Length);
              fStream.Close();
  
              web.AllowUnsafeUpdates = true;
              SPFolder rootFolder = web.GetFolder(spFolderUrl);
  
              string strUser = "spDomain\\adminUser1";
              SPUser userCreatedBy = web.EnsureUser(strUser);
  
              //This part sets the created by field successfully but fails to add files bigger than 150mb.
              SPFile file = rootFolder.Files.Add(item.Name, contents,userCreatedBy,userCreatedBy,DateTime.Now,DateTime.Now);
  
              int id = file.Item.ID;
              SPListItem listItem = file.Item;//docsLibrary.GetItemById(id);
              listItem["Created"] = item.CreationTime;
              listItem["Modified"] = item.LastWriteTime;
              listItem.Update();
  
              web.AllowUnsafeUpdates = false;
          }
      }
  });
  </code></pre>
  
  <p>It's also obvious that my second code block doesn't have the RequestTimeOut settings. Maybe this could be the reason why it couldn't upload bigger files. I wanted to set the RequestTimeOut, but <strong><em>how do I add it in my code or is there any other better approach to do this</em></strong>?</p>
  
  <p><strong>Business requirement:</strong> Programmatically upload files bigger than 150&nbsp;MB (300&nbsp;MB, 800&nbsp;MB and even 1&nbsp;GB up) to SharePoint Document Library and set the <em>Created By</em> field to whoever is the author of the file from the local source folder.</p>
  
  <p>Please let me know if there's anything that is not clear on my question so that I can update it.</p>