从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());
}
[解决办法]