
1,661 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
using (var ctx = new ClientContext(DataSharepointSite))
{
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = GetCreds();
using (FileStream fs = new FileStream(localFile, FileMode.Open))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, sharepointFile, fs, true);
}
//****************
// Now somehow set Modified Date to local File's Modified Date
//****************
var file = ctx.Web.GetFileByServerRelativeUrl(sharepointFile);
ListItem lstItem = file.ListItemAllFields;
ctx.Load(lstItem);
ctx.ExecuteQuery();
lstItem["CreatedDate"] = System.IO.File.GetCreationTime(localFile).ToUniversalTime();
lstItem.Update();
ctx.ExecuteQuery();
}
But I can't set into item, is there any wrong in the code ?
Hi @sp13test ,
Modify a bit in the code:
var file = ctx.Web.GetFileByServerRelativeUrl(sharepointFile);
ListItem lstItem = file.ListItemAllFields;
ctx.Load(lstItem);
ctx.ExecuteQuery();
lstItem["Created"] = System.IO.File.GetCreationTime(localFile).ToShortDateString();
lstItem.Update();
ctx.ExecuteQuery();
Thanks
Best Regards
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.