1

I've a file library on a sharepoint 2010. I'm using the Sharepoint library and I want to upload a file.

I found a lot of example about this, the problem is that I've some additional fields in the sharepoint file library, and I don't see how to specify them.

Here is one of the example I saw: http://msdn.microsoft.com/en-us/library/ms454491.aspx

One of these fields is mandatory so I've to set it when I add a file.

How can I do this?

Thank you!

J4N
  • 19,480
  • 39
  • 187
  • 340

1 Answers1

1

Here is a sample of how you might do this ("Method 2" in the example):

http://www.learningsharepoint.com/2010/07/12/programmatically-upload-document-using-client-object-model-sharepoint-2010/

In a nutshell, you need to upload the file first and then update any required metadata fields.

Rob
  • 1,060
  • 6
  • 12
  • But if fields are marked as mandatory, will the upload be possible? – J4N Jun 16 '11 at 12:22
  • I believe you should be able to upload and then update the required fields. You can do this through the SharePoint UI too. If you have a required field on your document library, you can upload a document without filling in the fields right away, however, you won't be able to check in the file until those fields are filled in. – Rob Jun 16 '11 at 12:35
  • So I tried: http://pastebin.com/2sSL9JVj But when I'm on the _context.ExecuteQuery(); I got an exception telling me that "the value isn't in the expected range". Any idea why? – J4N Jun 16 '11 at 12:45
  • Hmm. The info I sent you was for the client object model. Is that what you are using or are you needing to use the server object model? Here is another example that might help: http://philwicklund.com/Lists/Posts/Post.aspx?ID=12 – Rob Jun 16 '11 at 13:16
  • In facts, its because of the "\"+filename, if I remove "\" it works! – J4N Jun 16 '11 at 13:17