zoukankan      html  css  js  c++  java
  • How to bulk upload/copy a folder structure and files to SharePoint

    How to bulk upload/copy a folder structure and files to SharePoint

    So you’ve got a bunch of files nicely arranged in a folder structure sitting on your computer or a network drive that you want to copy up to a SharePoint library and preserve the directory structure. On the surface this is a daunting task as you can’t just give SharePoint your folder structure and tell it to do the work for you, so what are your options.

    Option 1: Manually via SharePoint IU

    Recreate the folder structure in SharePoint and upload the files via SharePoint UI in batches doing a multiple file upload to one destination folder at a time. Not much fun for anyone, but it can be done.

    Option 2: Commercial Tool

    Try a 3rd party tool. Yes they will probably cost you but will get the job done and probably with a few extra bell’s and whistles like applying metadata to SharePoint columns during the process. Some of the key companies to take a look at would be:

    Option 3: Open Source Tools

    There are some open source projects going around that claim to handle these types of bulk uploads, here’s a couple that look interesting:

    http://spbulkdocumentimport.codeplex.com/

    http://spfileupload.codeplex.com/

    Option 4: Script it Yourself

    PowerShell is an awesome way to get things done quickly in SharePoint, I’ve written these scripts in the past that show you how to create folders and how to upload documents to SharePoint. With a bit of extension and effort you could roll your own scripted solution.

    https://camerondwyer.wordpress.com/2013/05/27/how-to-import-upload-an-entire-folder-of-files-to-sharepoint-using-powershell/

    https://camerondwyer.wordpress.com/2013/11/06/sharepoint-powershell-how-to-create-sharepoint-library-folders-for-loadperformance-testing/

    Option 5: Explorer View

    The old ‘Open Library in Explorer View’ option in SharePoint may get you out of trouble if the directory structure and number of files is fairly small. Simply use the Explorer View to open the SharePoint library up in a Windows Explorer window and then copy/paste or drag/drop into the Window and the magic will start to happen

    Option 6: OneDrive for Business

    Now this is my preferred option for getting the job done, and the reason for writing this blog post! To achieve this one, browse to your library in SharePoint and click on the sync button to have the SharePoint library sync’d via OneDrive to your local machine.

    bulk-upload-folder-structure-sharepoint-cameron-dwyer-onedrive-sync-button

    After the sync has completed the SharePoint library (and it’s content including any folder structure) is now represented as a folder structure that you can easily get to through Windows Explorer.

    bulk-upload-folder-structure-sharepoint-cameron-dwyer-onedrive-local-library

    Now it’s just a matter of copy/paste or drag/drop your local folder structure (that you want to copy to SharePoint) into this folder in Windows Explorer. Here is my folder structure I want to copy up to SharePoint.

    bulk-upload-folder-structure-sharepoint-cameron-dwyer-folders-to-upload

    So I can just copy the “My Folder Structure” folder and paste it into the SharePoint sync library location. This is super quick because it’s just copying between 2 locations on your local hard drive.

    bulk-upload-folder-structure-sharepoint-cameron-dwyer-onedrive-sync

    Now the real goodness happens. OneDrive will sync the entire folder structure including any content files up to SharePoint in the background. You will notice that the folders and files you have just pasted have a tiny icon in the left corner. This will display a green tick when the item has been created in SharePoint. This is awesome, your computer is still free to use, there’s no lockup. If you need to shutdown before the sync is finished, it will just pick up from where it left off. OneDrive’s mission in life is to keep your local folder in sync with the SharePoint library, and it will work tirelessly in the background to do this.

    Another powerful advantage this method has over many of the other options I provided earlier is that it will work with Office 365 which you just can’t reach some of those other methods.

    Now my disclaimer before I get people throwing virtual rotten fruit at me. I’m not suggesting you use this method to move an entire network drive to SharePoint. Yes, I advocate you should take the opportunity to clean up the data on your network drives and not just move the problem to SharePoint. I also believe in the use of metadata to classify content rather than using folders. Having said that, there are valid instances when you do need to perform an upload of many files and preserve the folder structure in SharePoint and I think the OneDrive approach is a pretty cool tool to add to your arsenal.

    I often find myself scratching around the local drive of my development machines for remnants of PowerShell scripts to generate list & libraries in SharePoint with all sorts of different folder hierarchies to test the performance of code I’m working on to ensure it scales well once the folder & item counts start getting up to high numbers. So rather than keep scratching I’m going to start posting my scripts as I create and use them so I can find/reuse them later on and someone else might find them useful as well. I’m sure they won’t work under all scenarios and situations (and they are not designed to). They are just quick scripts that serve a specific purpose to me at the time and you may be able to tweak to fit your needs.

    Note this example doesn’t handle folders within folders. There are also several “no-code” methods for uploading a whole folder structure (and files) to SharePoint.

    1. Create a folder containing the files to upload to SharePoint

    files-to-import-upload-to-sharepoint-cameron-dwyer

    2. Locate the SharePoint library that you want to upload the files to, take note of the:

    • Web URL
    • Document library URL
    • Document library name

    3. Copy the following script to be run in a PowerShell window

    if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
    {
        Add-PSSnapin Microsoft.SharePoint.PowerShell
    }
    
    #Script settings
    
    $webUrl = "http://vs-server12"
    
    $docLibraryName = "Documents"
    $docLibraryUrlName = "Shared%20Documents"
    
    $localFolderPath = "C:	empDocs4SharePoint"
    
    #Open web and library
    
    $web = Get-SPWeb $webUrl
    
    $docLibrary = $web.Lists[$docLibraryName]
    
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    
    ForEach($file in $files)
    {
    
        #Open file
        $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
    
        #Add file
        $folder =  $web.getfolder($docLibraryUrlName)
    
        write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
        $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
        write-host "Success"
    
        #Close file stream
        $fileStream.Close();
    }
    
    #Dispose web
    
    $web.Dispose()
    

    4. Change the PowerShell variables at the top of the script to match your SharePoint upload destination and the location of the folder of files to upload

    powershell-variable-to-change-sharepoint-cameron-dwyer

    5. Run the PowerShell script, you should see progress of the uploaded files as shown below

    result-powershell-save-files-to-sharepoint

    6. After the script completes you should see all of the imported files in your SharePoint document library

    result-entire-folder-files-imported-to-sharepoint-cameron-dwyer

     

  • 相关阅读:
    windows查询占用端口的pid以及查询对应的进程名称
    [转]Android学习系列(29)App调试的几个命令实践
    [原]Android中接入微信客户端心得
    Robots.txt使用指南
    SqlHelper中使用事务
    QQ 影音,功能手札
    Access 2007数据库压缩和修复数据库功能
    dhl:PetShop里面的sqlHelper相关操作
    dhl:svn客户端学习TortoiseSVN的基本使用方法
    从 if else 到设计模式的转变
  • 原文地址:https://www.cnblogs.com/lingdanglfw/p/14550106.html
Copyright © 2011-2022 走看看