select downloaded file extention

G

ghighi

Hello, Il a downloading a file from a download.aspx page with that
code:

-----------------------------------------------------------------------------------------
string fileName = Request.Params["file"];
string fileExtension=fileName.Substring(fileName.Length-3);
string filePath = Path.Combine( "apath",fileName);
FileStream fs = new FileStream(filePath,
FileMode.Open,FileAccess.Read,FileShare.ReadWrite);

Response.AddHeader("Content-Disposition", "attachment;
filename="+System.Web.HttpUtility.UrlEncode(fileName));


Response.WriteFile(fs.Handle,0,fs.Length);
fs.Close();
Response.Flush();
---------------------------------------------------------------------------------

This code opens a "save as" window in witch I can select the path where
to save my file, change the file name and select the file extention
The default file type selected is "html document" while I would like it
to be "any file *.*"

What can I do in my code so that my "save as" widows is opened with the
"*.*" file type selected?
Thanks for any help,
G.
 
B

Ben Voigt

ghighi said:
Hello, Il a downloading a file from a download.aspx page with that
code:

-----------------------------------------------------------------------------------------
string fileName = Request.Params["file"];
string fileExtension=fileName.Substring(fileName.Length-3);
string filePath = Path.Combine( "apath",fileName);
FileStream fs = new FileStream(filePath,
FileMode.Open,FileAccess.Read,FileShare.ReadWrite);

Response.AddHeader("Content-Disposition", "attachment;
filename="+System.Web.HttpUtility.UrlEncode(fileName));


Response.WriteFile(fs.Handle,0,fs.Length);
fs.Close();
Response.Flush();
---------------------------------------------------------------------------------

This code opens a "save as" window in witch I can select the path where
to save my file, change the file name and select the file extention
The default file type selected is "html document" while I would like it
to be "any file *.*"

What can I do in my code so that my "save as" widows is opened with the
"*.*" file type selected?

Set the Content-Type header, probably to application/x-octetstream
 
G

ghighi

thks, it's perfect!

Ben Voigt a écrit :
ghighi said:
Hello, Il a downloading a file from a download.aspx page with that
code:

-----------------------------------------------------------------------------------------
string fileName = Request.Params["file"];
string fileExtension=fileName.Substring(fileName.Length-3);
string filePath = Path.Combine( "apath",fileName);
FileStream fs = new FileStream(filePath,
FileMode.Open,FileAccess.Read,FileShare.ReadWrite);

Response.AddHeader("Content-Disposition", "attachment;
filename="+System.Web.HttpUtility.UrlEncode(fileName));


Response.WriteFile(fs.Handle,0,fs.Length);
fs.Close();
Response.Flush();
---------------------------------------------------------------------------------

This code opens a "save as" window in witch I can select the path where
to save my file, change the file name and select the file extention
The default file type selected is "html document" while I would like it
to be "any file *.*"

What can I do in my code so that my "save as" widows is opened with the
"*.*" file type selected?

Set the Content-Type header, probably to application/x-octetstream
Thanks for any help,
G.
 

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

Top