首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

从sharepoint asset library下载文件为什么总是花了很长的时间?解决思路

2012-03-22 
从sharepoint asset library下载文件为什么总是花了很长的时间?我在我的项目中使用了一个button,叫downloa

从sharepoint asset library下载文件为什么总是花了很长的时间?
我在我的项目中使用了一个button,叫download,里面会去根据一个url去下载这个文件,代码如下,现在的问题是为什么在IE8下面会花费很长时间(接近半分钟),在火狐下一瞬间就下载完毕了,我的代码是不是有什么问题?
求解释。。。 求高手!

 public void OpenAttachment(string url, string picName)
  {
  try
  {
  //set the content type of file according to extension
  string[] fext = picName.Split('.');

  // Get the extension of File to determine the file type
  string casestring = "";
  if (fext.Length > 1)
  {
  casestring = fext[fext.Length - 1];
  }

  SPWeb web = SPContext.Current.Web;
  web.AllowUnsafeUpdates = true;
  string contentType = "";

  SPFile tempFile = web.GetFile(url);

  byte[] obj = (byte[])tempFile.OpenBinary();
  switch (casestring)
  {

  case "jpg": contentType = "image/jpeg";

  break;

  case "jpeg": contentType = "image/jpeg";

  break;

  case "gif": contentType = "image/gif";

  break;

  case "bmp": contentType = "image/bmp";

  break;

  case "png": contentType = "image/x-png";

  break;

  case "tif": contentType = "image/tiff";

  break;

  case "flv": contentType = "video/x-flv";

  break;
  }

  HttpContext.Current.Response.ClearContent();
  HttpContext.Current.Response.ClearHeaders();
  HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename= " + picName);
  HttpContext.Current.Response.ContentType = contentType;

  //Check that the client is connected and has not closed the connection after the request

  if (HttpContext.Current.Response.IsClientConnected)
  HttpContext.Current.Response.BinaryWrite(obj);

  HttpContext.Current.Response.Flush();
  HttpContext.Current.Response.Close();

  web.AllowUnsafeUpdates = false;
  }

  catch (Exception ex)
  {
  Response.Write(ex.ToString());
  }

[解决办法]

探讨
比如你想下载 http://server/doclib/a.jpg 这个文件,你可以用js或者后台代码直接跳转到 http://server/_layouts/download.aspx?SourceUrl=/doclib/a.jpg
不用你自己写这个页面

热点排行