#use SOAP::Lite (+trace => all, maptype => {});
use SOAP::Lite maptype => {};
use LWP::UserAgent;
use HTTP::Request::Common;
#credentials' file
require "c:\\test\\pass.pl";
my $userAgent = LWP::UserAgent->new(keep_alive => 1);
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return $username => $password;
}
my $soap
= SOAP::Lite
->uri('<mysite>/_vti_bin/lists.asmx')
->on_action(sub {join '/', 'http://schemas.microsoft.com/sharepoint/soap/CopyIntoItemsLocal', $_[1]})
->proxy('<mysite>/_layouts/viewlsts.aspx?BaseType=0', keep_alive => 1);
# my $method = SOAP::Data->name('CopyIntoItemsLocal')
# ->attr({xmlns => 'http://schemas.microsoft.com/sharepoint/soap/'});
# my @params = (SOAP::Data->name(SourceUrl => $source),
# SOAP::Data->name(DestinationUrl => $destination));
# print $soap->call($method => @params)->result;
my $fileName = 'c:\test\abc.txt';
my $destDir = "<mysite>/Lists/sharepoint1/";
#load and encode Data
my $data;
open(FILE, $fileName) or die "$!";
#read in chunks of 57 bytes to ensure no padding in the middle (Padding means extra space for large files)
while (read(FILE, $buf, 60 * 57)) {
$data .= encode_base64($buf);
}
close(FILE);
#make the call
print "uploading $fileName...";
$lists = $soap->GetList();
my $method = SOAP::Data->name('CopyIntoItemsLocal')->attr({xmlns => 'http://schemas.microsoft.com/sharepoint/soap/'});
my @params = (
SOAP::Data->name('SourceUrl')->value($fileName)->type(''),
SOAP::Data->name('DestinationUrls')->type('')->value(
\SOAP::Data->name('string')->type('')->value($destDir . $fileName)
),
SOAP::Data->name('Fields')->type('')->value(
\SOAP::Data->name('FieldInformation')->type('')->attr({Type => 'File'})->value('')
),
SOAP::Data->name('Stream')->value("$data")->type('')
);
#print Results
print $soap->call($method => @params)->result;
#print $response->headerof('//CopyResult')->attr->{ErrorCode};
#use SOAP::Lite (+trace => all, maptype => {});
use SOAP::Lite maptype => {};
use LWP::UserAgent;
use HTTP::Request::Common;
use MIME::Base64 qw(encode_base64);
require "c:\\test\\pass.pl";
my $userAgent = LWP::UserAgent->new(keep_alive=>1);
#setup connection
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return $username => $password;
}
my $soap = SOAP::Lite
-> uri('http://<mysite>')
-> on_action(sub{ join '/', 'http://schemas.microsoft.com/sharepoint/soap', $_[1] })
-> proxy('http://<mysite>/_vti_bin/lists.asmx',keep_alive => 1);
$lists = $soap->GetListCollection();
quit(1, $lists->faultstring()) if defined $lists->fault();
my @result = $lists->dataof('//GetListCollectionResult/Lists/List');
foreach my $data (@result) {
my $attr = $data->attr;
foreach my $a qw'Title Description DefaultViewUrl Name ID WebId ItemCount' {
printf "%-16s %s\n", $a, $attr->{$a};
}
print "\n";
}
認證似乎是工作。首先,我認爲GetlistCollection
Web服務正在工作,因爲當我使用該Web服務進行呼叫時,它返回了一個頁面。但我認爲該電話正在返回我在proxy
參數中指定的頁面。如何使用Perl SOAP :: Lite將文件從本地機器上傳到Sharepoint?
我能夠獲取特定站點上的SharePoint列表的集合。
我已經使用了GetListCollection。但是我並沒有真正理解打印列表的代碼。我只是從squish.net複製它。現在我正在嘗試使用CopyIntoItemsLocal
Web服務。
我們有一個服務器上的文件存儲庫(SVN),我必須編寫一個Perl腳本,它在執行時會將文件和目錄從SVN複製到共享點以及目錄結構。
我會感謝任何幫助或提示。既然這是一個很大的任務,我正在模塊化。
幫助我們來幫助你。在這裏展開你的問題。你提供了一些代碼,但告訴我們你期望發生什麼,以及發生了什麼。 – lhagemann
我已經嘗試過,但沒有運氣(http://stackoverflow.com/questions/4277340/accessing-a-sharepoint-using-perl-and-webdav)。我最終使用從Perl調用的PowerShell(http://stackoverflow.com/questions/4657954/how-to-access-lists-of-a-sub-site-in-sha- point-using-web-services,http:/ /www.nivot.org/nivot2/post/2008/02/29/ManipulatingRemoteSharePointListsWithPowerShell.aspx) – eckes
我在前面的代碼下面包含了代碼。對於那個很抱歉。我無法弄清楚如何在單獨的章節中包含新代碼。 – Harpreet