。
可以解析好像列表的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)
一旦你下載了可以解析雖然文件的文件 - 一個快速谷歌打開了李霍姆斯做了大部分已經:
http://www.leeholmes.com/blog/2005/09/05/unit-testing-in-powershell-%E2%80%93-a-link-parser/
你想要的主位是正則表達式:
$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
}
文件是否在列表中?你可以得到,通過它解析,然後單獨下載文件... – Matt
是的文件在列表中。但是,如何解析列表中的thrun?無法使用SharePoint WebService。 – LaPhi
爲什麼不能使用Web服務?規範的答案是調用列表web服務的GetListItems方法,它將爲您提供文檔庫中項目的URL。然後,您可以使用它們與WebClient下載它們。 –