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 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);
context.Load(context.Web);
List docList = context.Web.Lists.GetByTitle("MyDocLib");
context.Load(docList);

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
add comment

1 Answer

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!";
item.Update();

References:

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
add comment

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.