Click here to Skip to main content
15,877,915 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all,


I have a requirement like programatically i have to upload files and folder from files system to sharepoint 2010 document library.


Condition is:user will pass the following parameters in the config file:
1)Source folder location(from file system)
2)Destination sharepoint site URL.
3)Sharepoint Document Library Name.


Now using object model or web service how can we upload the folder contains from source to destination(doc library) which will have same folder hierarchy as like source hierarchy in file system.Thanks in advance, any help is appreciated.
Posted

1 solution

Create Site and Web Objects and write this code below:


C#
SPFolder myLibrary = Web.Folders[documentLibraryName];

// Prepare to upload
Boolean replaceFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload location);
FileStream fileStream = File.OpenRead(fileToUpload location);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceFiles);

// Commit 
myLibrary.Update();


Hope this helps.

For more SharePoint help log on to http://blog.sharepointclick.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900