Sharepoint web service 下载大文档出错
本帖最后由 QiXing_Gan 于 2013-03-28 11:41:13 编辑 朋友们好,我这里遇到了麻烦,希望得到大家的帮助。
我的需求是这样的,开发winform程序,程序中有个功能是下载SharePoint文档库中的文档。所以,毫无疑问,自然要用到SharePoint 的 web service来实现了,即Copy.asmx。
我的代码是这样的:
public static void CopyfileToLocal(string strSiteUrl,string strFileUrl, string strFilePath)
{
using (Copy copyFile = new Copy())
{
if (AdminNwc == null)
{
return;
}
copyFile.Credentials = AdminNwc;
copyFile.Url = strSiteUrl.Trim('/') + @"/_vti_bin/Copy.asmx";
FieldInformation fileInfo = new FieldInformation();
FieldInformation[] fileInfoArray = { fileInfo };
byte[] fileContents;
copyFile.GetItem(strFileUrl, out fileInfoArray, out fileContents);
}
}
//
// CopyStream is from
// http://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file
//
public static void CopyStream(Stream input, Stream output) {
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0) {
output.Write(buffer, 0, len);
}
}
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://myserver.com/test/Shared%20Documents/mypic.jpg";
WebRequest request = WebRequest.Create(new Uri(url, UriKind.Absolute));
request.UseDefaultCredentials = true;
WebResponse response = request.GetResponse();
Stream fs = response.GetResponseStream() as Stream;
using (FileStream localfs = File.OpenWrite(@"c:\temp\aspdownloadedfile.jpg"))
{
CopyStream(fs, localfs);
}
}