I want to know if i can upload a document to sharePoint document library using batch in C#. I know how to update and delete it using batch, but i don't know how to upload it.

If i can't, what is the best way to upload a document with metadata?

Thanks alot.

3 Answers 3


I think it can't be done. So i did the following:

1- I uploaded a document to the document library using a web request.
2- I updated the metadata of this document using the batch update command.

If anyone have a different approach please share it.



I don't know how to add metadata. But to upload a document you can map the document library to an unused drive letter and copy the file to the document library

net use x: \\path\to\sharepoint\document\library
copy foo.bar x:

Here follow some code snippet to help you with file upload... Considering that you'll upload to a Document Library...

    spWeb.AllowUnsafeUpdates = True

    Dim strUrl As String = spWeb.Lists("DocLib").RootFolder.ServerRelativeUrl.ToString()

    Dim spFolderCollection As SPFolderCollection = spWeb.GetFolder(strUrl).SubFolders

    Dim spFolder As SPFolder = spFolderCollection.Item("FolderName")

    spFolder.Files.Add(fileName, stream, replaceExistingFiles)


    spWeb.AllowUnsafeUpdates = False
End Try

Your Answer

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