下面的代碼上傳了一個PDF文檔庫。這可能是對你有所幫助
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script><script src="/Style%20Library/jquery.SPServices-0.6.2.min.js" type="application/javascript"></script><script src="/Style%20Library/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function uploadFile() {
var filePath = "c:\\test.pdf";
var url= "http://Site/Shared Documents/test.pdf";
var soapEnv =
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body>\
<CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
<SourceUrl>" + filePath + "</SourceUrl>\
<DestinationUrls>\
<string> "+ url + "</string>\
</DestinationUrls>\
<Fields>\
<FieldInformation Type='Text' DisplayName='Title' InternalName='Title' Value='Test' />\
</Fields>\
<Stream>base64Binary</Stream>\
</CopyIntoItems>\
</soap:Body>\
</soap:Envelope>";
$.ajax({
url: "http://site/_vti_bin/copy.asmx",
beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
alert(soapEnv);
}
function processResult(xData, status) {
alert("Uploaded SuccessFully");
}
</script>
<input name="Upload" onclick="uploadFile()" type="button"/>
你確定嗎?我用Firefox測試和文件被創建到文檔共享庫,但它包含1KB時,我的原始文件是15KB,且內容已損壞...... – AymKdn