SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a Silverlight Application that runs in a SharePoint 2010 web part.

One requirement I have is to give the user a prompt to upload a file, and then send it into a specific Document Library with the additional Fields 'First' and 'Last' (Name corresponding to whom the document is from).

I am able to create the document and upload it to SharePoint. At this point however I hit an impasse. The normal means (as far as I'm aware) to add a Document to a Document Library is something similar to the following...

ClientContext context = new ClientContext(ApplicationContext.Current.Url);
List docList = context.Web.Lists.GetByTitle("MyDocLib");

docList.RootFolder.Files.Add(myFile); // Assuming of course the file is retrieved already
context.ExecuteQuery(); // Or ExecuteQueryAsync for more functionality

Unfortunately this leaves no room to add in the extra fields i need.

Furthermore the only thing received if i were to use something like

File file = docList.RootFolder.Files.Add(myFile);

does not seem to have an association with the library to build off of and then run another ExecuteQuery()

I would imagine there would be a way of treating the Document Library as a List (I'm fairly sure from a technical perspective they amount to the same thing) for its item creation, however I do not know how to create it properly.

If someone could give me advice on how to proceed, it would be much appreciated.

Thank you

share|improve this question
up vote 3 down vote accepted

You're almost there, using your Files.Add method as shown you can then set properties like this:

File file = docList.RootFolder.Files.Add(myFile);
ListItem item = file.ListItemAllFields;
item["Title"] = "Super Awesome File!";


share|improve this answer
Great! Thanks, I'll try it right now and then set it as an answer! – Zork Mar 16 '12 at 17:42
Worked perfectly, thanks again! – Zork Mar 16 '12 at 17:56

Your Answer


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.