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 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.

share|improve this question

3 Answers 3

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:
share|improve this answer
up vote 1 down vote accepted

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.

Thanks.

share|improve this answer

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

Try
    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)

    spFolder.Update()

Finally
    spWeb.AllowUnsafeUpdates = False
End Try
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.