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'm a beginner with SP COM. I can't find any samples about this online.

Could anybody tell me how I should proceed to add or remove a file from a document library in SP 2010 with the Client Object Model?


share|improve this question

To add a document to a document library in VB.Net:

Imports SP = Microsoft.SharePoint.Client

Public Sub LoadFileToLibrary()
    Dim clientContext As SP.ClientContext = GetYourContext()
    Dim fileContent As Byte() = GetYourByteArrayOfYourFilesContents()

    Dim fileCreationInfo As SP.FileCreationInformation = New SP.FileCreationInformation()
    fileCreationInfo.Content = fileContent
    fileCreationInfo.Overwrite = True
    fileCreationInfo.Url = "Your full destination URL here including file name"

    Dim file As SP.File
    Dim folder As SP.Folder = list.RootFolder

    file = folder.Files.Add(fileCreationInfo)
End Sub

Same classes and everything in C# too. Should be easy enough to translate this snippet.

To delete a document, you can use the same code you would use to delete a list item (because a document library is just a special type of list). You should read How to: Create, Update, and Delete List Items.

Hope this helps.

share|improve this answer

This should get you started on uploading a file in SharePoint with the Client Object Model:

share|improve this answer

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.