2012-03-30 107 views

回答

4

試試這段代碼:請嘗試下面的功能。您需要通過FileURL(文檔的完整網址),Title(標題)(您要給予下載文件的通過名稱)。

(注意:此功能需要傳遞證書以及您要下載的文檔的完整url 。我認爲這對你來說已經足夠了)

public string DownLoadfiletolocal(string FileURL, string Title) 
{ 

//Copy.Copy is a webservice object that I consumed. 

Copy.Copy CopyObj = new Copy.Copy(); 
CopyObj.Url = SiteURL + "/_vti_bin/copy.asmx"; // Dynamically passing SiteURL 
NetworkCredential nc2 = new NetworkCredential(); 
nc2.Domain = string.Empty; 
nc2.UserName = _UserName; 
nc2.Password = _Password; 


string copySource = FileURL; //Pass full url for document. 

Copy.FieldInformation myFieldInfo = new Copy.FieldInformation(); 
Copy.FieldInformation[] myFieldInfoArray = { myFieldInfo }; 
byte[] myByteArray; 

// Call the web service 
uint myGetUint = CopyObj.GetItem(copySource, out myFieldInfoArray, out myByteArray); 

// Convert into Base64 String 
string base64String; 
base64String = Convert.ToBase64String(myByteArray, 0, myByteArray.Length); 

// Convert to binary array 
byte[] binaryData = Convert.FromBase64String(base64String); 

// Create a temporary file to write the text of the form to 
string tempFileName = Path.GetTempPath() + "\\" + Title; 

// Write the file to temp folder 
FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite); 
fs.Write(binaryData, 0, binaryData.Length); 
fs.Close(); 

return tempFileName; 

} 
+0

謝謝,如果我已經可以獲取文檔庫中的文檔列表,我會使用你的代碼。 – float 2012-03-30 12:12:59

+0

我添加了對copy.asmx服務的服務引用,但沒有複製接口。只有CopySoap。 – float 2012-03-30 12:18:45

+1

使用Web參考添加此服務沒有添加在服務參考 – 2012-03-30 12:25:16

相關問題