zoukankan      html  css  js  c++  java
  • SharePoint 2010 Powershell 上传本地目录文件夹到文档库 Poweshell upload files to document library

    Function Ipmort-OSCFolder
    {

     param
     (
     [string]$siteurl,
     [string]$Library,
     [string]$path
     )
     $spWeb = Get-SPWeb $siteurl
     $spDocumentLibrary = $spWeb.Lists[$Library] 
     If($spDocumentLibrary)
     {
      $Fol = Get-Item -Path $path
      $result = $spDocumentLibrary.ParentWeb.GetFolder($spDocumentLibrary.RootFolder.ServerRelativeUrl +"/"+ $Fol.Name )
      If($result.Exists -eq "True")
      {
       Write-Warning "There is a folder existing on site $siteUrl."
      }
      Else
      {
       $SPFol = $spDocumentLibrary.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$Fol.Name)
       $SPFol.Update()
       SubFolder $path $SPFol $spDocumentLibrary
      }
     }
     Else
     {
      Write-Warning "There is no library named $Library on site $siteurl."
     }

    }

    Function SubFolder($Folder,$SPFol,$spDocumentLibrary)
    {
     $SPFolder = $spDocumentLibrary.ParentWeb.GetFolder($SPFol.Folder.ServerRelativeUrl)
     $Objects = Get-ChildItem -Path $Folder
     Foreach($obj in $Objects)
     {
      If($obj.PSIsContainer)
      { 
       $SubFolder = $spDocumentLibrary.AddItem($SPFolder.ServerRelativeUrl,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$obj.Name)
       $SubFolder.Update()
       $Fullname = $obj.FullName
       SubFolder $Fullname $SubFolder $spDocumentLibrary
       
      }
      Else
      { 
       $fileStream = ([System.IO.FileInfo]$obj).OpenRead()
       $contents = new-object byte[] $fileStream.Length
       $FolderObj = $spDocumentLibrary.ParentWeb.GetFolder($SPFolder.ServerRelativeUrl)
       $SpFile = $FolderObj.Files.Add($FolderObj.Url + "/"+$obj.Name, $contents, $true)
       $spItem = $SpFile.Item
      }
     }

    }

    Ipmort-OSCFolder -siteurl "http://win-lfseeatt8jr/sites/myteam" -Library "Shared Documents" -path  "C:\Users\Administrator\Desktop\Test"

  • 相关阅读:
    洛谷 3393 逃离僵尸岛
    洛谷 3275 [SCOI2011]糖果
    SP1437 Longest path in a tree(树的直径)
    洛谷2483 k短路([SDOI2010]魔法猪学院)
    洛谷3243 [HNOI2015]菜肴制作
    洛谷 4568 [JLOI2011] 飞行路线
    [USACO08DEC]在农场万圣节Trick or Treat on the Farm
    手机端table表格bug
    手机端左右滑动效果
    去掉手机端延迟300ms
  • 原文地址:https://www.cnblogs.com/ahghy/p/3096853.html
Copyright © 2011-2022 走看看