public void UploadMasterPage(ClientContext Context, string FolderRelativeURL, string RelativeItemUrl, string SourceFilePath) { FileCreationInformation fci; var web = Context.Web; List gallery = null; using (var stream = System.IO.File.OpenText(SourceFilePath).BaseStream) { fci = new FileCreationInformation { ContentStream = stream, Url = RelativeItemUrl, Overwrite = true }; //Get master Page Gallery list, rootfolder and subfolders gallery = web.Lists.GetByTitle("Master Page Gallery"); Context.Load(gallery); Context.Load(gallery.RootFolder); Context.Load(gallery.RootFolder.Folders); //Get DI sub-folder FolderCollection fc = gallery.RootFolder.Folders; Folder DI = fc.GetByUrl("DI"); Context.Load(DI.Folders); //Get MasterPage sub-folder FolderCollection mps = DI.Folders; Folder MasterPage = mps.GetByUrl("MasterPage"); Context.Load(MasterPage); Microsoft.SharePoint.Client.File newFile = MasterPage.Files.Add(fci); Context.Load(newFile); Context.ExecuteQuery(); } ListItem item = GetItemFromListByUrl(Context, gallery, fci.Url); var masterPageHTMLCT = GetContentType(Context, gallery, "Html Master Page"); item["ContentTypeId"] = masterPageHTMLCT.Id.StringValue; item["UIVersion"] = Convert.ToString(15); item["MasterPageDescription"] = "Custom MoD DI MasterPage"; item.Update(); Context.Load(item); Context.ExecuteQuery(); }