File download size limit

G

Guest

I have a site that allows a person to log in and get a list of files to
download for them. If the file size is under 65MB then everything is fine,
they click the download button and the save box pops up. But if the file is
larger than 65MB the page sits and processes until it times out. I can't
figure it out becaus a 64MB file loads immediately for download while one
slightly larger hangs up. Below is the code I am using for the download.


FileInfo targetFile = new FileInfo(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" +
targetFile.Name);
Response.AddHeader("Content_Length", targetFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(targetFile.FullName);
Response.End();


Any assistance on this will be greatly appreciated. Tim
 
J

Joerg Jooss

Thus wrote tjfdownsouth,
I have a site that allows a person to log in and get a list of files
to download for them. If the file size is under 65MB then everything
is fine, they click the download button and the save box pops up. But
if the file is larger than 65MB the page sits and processes until it
times out. I can't figure it out becaus a 64MB file loads immediately
for download while one slightly larger hangs up. Below is the code I
am using for the download.

FileInfo targetFile = new FileInfo(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;
filename=" +
targetFile.Name);
Response.AddHeader("Content_Length",
targetFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(targetFile.FullName);
Response.End();
Any assistance on this will be greatly appreciated. Tim

Try using Response.TransmitFile() instead of WriteFile(). TransmitFile()
doesn't buffer the file.

Cheers,
 
G

Guest

That did the trick, Thanks
Tim

Joerg Jooss said:
Thus wrote tjfdownsouth,


Try using Response.TransmitFile() instead of WriteFile(). TransmitFile()
doesn't buffer the file.

Cheers,
 
Joined
Mar 14, 2008
Messages
2
Reaction score
0
similar problem

I have a simlar problem with the site i am working on, any files under 64MB work fine and it immediately loads the file for download, over 65MB the page times out.

the download.aspx file i am using is as follows:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Website.Website
{
public partial class Download : System.Web.UI.Page
{

protected void Page_Load(object sender, System.EventArgs e)
{

string strFileName = Request.QueryString["FileName"];
string strDownloadPath = "c:\\Inetpub\\wwwroot\\extras\\";
FileInfo objFI = new FileInfo(strDownloadPath + strFileName);

if(IsSafeFileToDownload(strFileName) && objFI.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + objFI.Name);
Response.AddHeader("Content-Length", objFI.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(objFI.FullName);
Response.End();
}
else
{
lblError.Text = "An error occurred trying to download your file, are you sure it exists?";
}
}

private bool IsSafeFileToDownload(string strFileName)
{
if(strFileName == null)
{
return false;
}
else if(Regex.IsMatch(strFileName, "\\w{0,16}\\.(pdf|gif|jpg|rtf|txt|mp3|wmv|m4a|mov|zip|iso)$"))
{
return true;
}
else
{
return false;
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{

}
#endregion
}
}


Any help with this would be amazing, thankyou
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top