朋友们好,我这里遇到了麻烦,希望得到大家的帮助。
我的需求是这样的,开发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);
}
}
(备注:这里关于创建Copy对象都有引用相应的命名空间)
以上代码在执行过程中,小文件都是没有问题的。但遇到了大文件就会抛异常,例如,下载一个180M的文件,里面出错:Exception of type 'System.OutOfMemoryException' was thrown.
请各位园友伸出援助之手。谢谢,不甚感激!
sharepoint web?service copy.asmx Copy.GetItem()
------解决方案--------------------
用Web service下载大文件肯定会内存溢出,试试:
//
// 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);