0

I am uploading files on a SharePoint folder with this code:

var clientContext = GetClientContext();
var folderName = "Folder";
var fileName = @"C:\Users\user\Desktop\file.pdf";
folder = clientContext.Web.Folders.GetByUrl(clientContext.Url + '/' + folderName);
var info = new FileCreationInformation
            {
                ContentStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read),
                Overwrite = false,
                Url = clientContext.Url + '/' + folderName + '/' + Path.GetFileName(fileName),
            };
file = folder.Files.Add(info);
folder.Update();
clientContext.Load(file, f => f.ListItemAllFields);
clientContext.ExecuteQuery();
clientContext.Load(file);
fileID = file.ListItemAllFields.Id;

And I see that they have no title once they get uploaded (they only have a name).

How can I set the Title too?

1

After upload you need to set it using

clientContext.Load(file);

ListItem item = file.ListItemAllFields;
item["Title"] = "Title";
item.Update();
clientContext.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.