使用SharePoint copy.asmx下载文件时的问题

0 投票
1 回答
2373 浏览
提问于 2025-04-16 12:49

我正在尝试通过一个叫做copy.asmx的SharePoint网络服务下载文件,这个文件只有100KB大小。

但是文件下载不下来。

这个网络服务的响应中返回的是一个空的流(out byte[] Stream),这可能是内存的问题。

而且它还返回了“download_document()内存不足”的提示。

注意:我是在使用MFP打印机查看这个应用程序。

1 个回答

0

请试试下面这个函数。你需要传入文件的链接(也就是文档的完整网址)和标题(你想给下载的文件起的名字)。

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;

}

撰写回答