Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

After upload you need to set it using

clientContext.Load(file);

ListItem item = file.ListItemAllFields;
item["Title"] = "Title";
item.Update();
clientContext.ExecuteQuery();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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