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?


2 Answers 2


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.


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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