Recursively upload files and folders to SharePoint

Source: Internet
Author: User
ArticleDirectory
    • Microsoft. SharePoint
    • Upload documents to the document library
    • Createdirectories (string path, spfoldercollection ofoldercollection)
    • Local folder
    • SharePoint Document Library
    • Running result
    • Restrictions

If you use SharePoint 2010, you can directly "upload multiple files ". In the displayed dialog box, you can drag and drop the entire folder. As shown in:

For SharePoint 2007, you can use the "Resource Manager" view to drag and drop folders like managing local files in the resource manager.

The method described below is the following. Of course, the next step is to manually create a folder to upload files one by one. You can use the SharePoint object model or web services to write a recursion program.ProgramTo upload files from a local folder to a Sharepoint library. Here we demonstrate how to upload an object model to a Sharepoint 2010 site.CodeIt is also available for Sharepoint 2007 sites. The only difference is 32-bit and 64-bit. The corresponding. NET Framework Version and Microsoft. Sharepoint. dll version.

Microsoft. SharePoint

Reference Microsoft. Sharepoint. DLL to access the SharePoint object model.

Upload documents to the document library
Try {localpath = txtlocalpath. text; // local path sharepointsite = txtserverurl. text; // SharePoint website url.doc umentlibraryname = txtlibrary. text; // SharePoint document library name. // obtain your SharePoint website object. using (spsite osite = new spsite (sharepointsite) {oweb = osite. openweb (); createdirectories (localpath, oweb. folders [documentlibraryname]. subfolders) ;}} catch (exception ex) {MessageBox. show ("error:" + ex. message );}
Createdirectories (string path, spfoldercollection ofoldercollection)

The createdirectories method is a recursive method that receives two parameters. The path parameter specifies the source location in the file system of the Local Computer; The ofoldercollection parameter specifies the target folder set. For usage of spfoldercollection, refer to here.

 

Private void createdirectories (string path, spfoldercollection ofoldercollection) {// upload multiple documents foreach (fileinfo ofi in new directoryinfo (PATH ). getfiles () {filestream = file. openread (OFI. fullname); spfile = ofoldercollection. folder. files. add (OFI. name, filestream, true); spfile. update ();} // upload multiple folders foreach (directoryinfo Odi in new directoryinfo (PATH ). getdirectories () {string sfoldername = Odi. fullname. split ('\') [Odi. fullname. split ('\\'). length-1]; spfolder spnewfolder = ofoldercollection. add (sfoldername); spnewfolder. update (); // recursively call to create a sub-Folder createdirectories (Odi. fullname, spnewfolder. subfolders );}}
Restrictions on running results of local folder SharePoint Document Library
    • The size of the file to be uploaded cannot exceed 2 GB.
    • The user executing the Code must have the upload permission for the corresponding document library.

References

Uploading files and folders recursively to a SharePoint site

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.