我想将多个文件从SharePoint库复制到本地目录。可以使用通配符吗?以下代码不起作用。但是有没有办法使用WebClient和通配符呢?(我必须使用WebClient。无法使用SharePoint WebServices :-( )
$url = "http://mySharePoint/websites/Site/TestDocBib/*.jpg"
$path = "D:\temp\"
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true
$WebClient.DownloadFile($url, $path)发布于 2011-07-14 21:13:00
您可以通过列表的html进行解析。
# dummy url - i've added allitems.aspx
$url = "http://mySharePoint/websites/Site/TestDocBib/allitems.aspx"
$path = "D:\temp\"
$dl_file = $path + "allitems.html"
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true
$WebClient.DownloadFile($url, $dl_file)下载完文件后,你就可以解析该文件了--谷歌很快就查到了Lee Holmes已经完成了大部分工作:
http://www.leeholmes.com/blog/2005/09/05/unit-testing-in-powershell-%E2%80%93-a-link-parser/
您需要的主要部分是regex:
$regex = “<\s*a\s*[^>]*?href\s*=\s*[`"']*([^`"'>]+)[^>]*?>” 我很快就破解了--这可能(也可能不)起作用……但要点在这里:)
$test = gc $dl_file
$t = [Regex]::Matches($test, $regex, "IgnoreCase")
$i = 0
foreach ($tt in $t) {
# this assumes absolute paths - you may need to add the hostname if the paths are relative
$url = $tt.Groups[1].Value.Trim()
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true
$WebClient.DownloadFile($url, $($path + $i + ".jpg"))
$i = $i + 1
}发布于 2011-07-14 17:50:28
不,对不起,您不能在WebClient中使用通配符。它不是HTTP的一部分。
发布于 2011-07-14 22:07:54
使用WEBDAV怎么样?
c:\> copy \\my.sharepoint.site\sites\foo\doclib\*.jpg c:\temp\如果客户端(即非sharepoint)是服务器2008+平台,则需要添加“桌面体验”角色并启用"webclient“服务。这与system.net.webclient不是一回事;它是HTTP/DAV网络重定向器服务。
如果您需要使用不同的凭据登录,您可以使用以下方式:
c:\> net use * "http://my.sharepoint.site/sites/foo/doclib" /user:foobar
mapped h: to ...
c:\> copy h:\*.jpg c:\temp希望这能有所帮助。
https://stackoverflow.com/questions/6691272
复制相似问题