Forum Discussion
Jason Chan
May 05, 2017Copper Contributor
Pnp-sites-core upload file with custom modified and created field
When using the Pnp-Powershell Add-PnpFile cmdlet, we can upload a file and alter the Created or Modified field at the same time. e.g. I can change the Modified field on the uploaded file PS:> A...
May 05, 2017
The PowerShell Cmdlet uses the following code:
Microsoft.SharePoint.Client.File file;
if (ParameterSetName == "AsFile")
{
file = folder.UploadFile(FileName, Path, true);
}
else {
file = folder.UploadFile(FileName, Stream, true);
}
if (Values != null)
{
var item = file.ListItemAllFields;
foreach (var key in Values.Keys)
{
item[key as string] = Values[key];
}
item.Update();
ClientContext.ExecuteQueryRetry();
}So you could use the same.
- Jason ChanMay 05, 2017Copper ContributorThanks, just wanna know if pnp-sites-core have handy extension doing the same thing with fewer line of code...
- May 05, 2017
AFAIK, there isn't any.