By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

Force Dialog Box when sending file to client

P: 1
I'm trying to download a text file to the client and all I can get it to do is open the file here is my code:

public void getFile(string strFileName)

string strPath = System.Web.HttpContext.Current.Server.MapPath(strF ileName);
System.IO.FileInfo file = new FileInfo(strPath);

if (file.Exists)

System.Web.HttpContext.Current.Response.ContentTyp e = "text/plain";

System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition", "attachement; filename=" + file.Name);
//System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition", "inline; filename=" + file.Name);

System.Web.HttpContext.Current.Response.AddHeader( "Content-Length", file.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile( file.FullName);

System.Web.HttpContext.Current.Response.TransmitFi le(System.Web.HttpContext.Current.Server.MapPath(s trFileName));



I'm using this in a class file.
Jan 4 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.