Downloading Files - Forcing the File Download Dialog
page 1 of 1
Published: 03 Nov 2003
Unedited - Community Contributed
Abstract
Ever try to force the "Download File" dialog in a clients's browser window when you download files that may be supported with a MIME type? Here is an example that works with many versions of IE.
by Steve Sharrock
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 617791/ 1817

This example illustrates a simple technique to download files of any type from you web application to the client browser. In addition to setting the MIME types, the example shows how to force the Download File dialog that allows the user to either run or save the file, even if the file type would normally display in the browser's window.

On my personal site (http://www.sharkcode.com ), I allow the user to download my resume in various formats including Microsoft Word, HTML, Rich Text and Plain Text. I found that for most users (with IE) the correct application was automatically used to view the document from within their browser (such as Word types like .doc). In all cases, however, I wanted the file to be saved to the client's workstation, rather than simply being displayed by the browser. When I hosted my own site, I could do this by setting the HTTP Headers with "content-disposition" to force the Download File dialog. Now, using the .NET Response object, I can set these headers directly.

The basic ingredients of this example are quite simple and can be found in a Microsoft article at (http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;q306654&lex).

The Microsoft article includes the following code snippet:

private void Page_Load(object sender, System.EventArgs e)
{
  //Set the appropriate ContentType.
  Response.ContentType = "Application/pdf";
  //Get the physical path to the file.
  string FilePath = MapPath("acrobat.pdf");
  //Write the file directly to the HTTP content output stream.
  Response.WriteFile(FilePath);
  Response.End();
}

I used this example to write a simple method that accepts a file name as input and a boolean that will force the File Download dialog which allows the client to either run, or save this file to their local workstation.

private void DownloadFile( string fname, bool forceDownload )
{
  string path = MapPath( fname );
  string name = Path.GetFileName( path );
  string ext = Path.GetExtension( path );
  string type = "";
  // set known types based on file extension  
  if ( ext != null )
  {
    switch( ext.ToLower() )
    {
    case ".htm":
    case ".html":
      type = "text/HTML";
      break;
  
    case ".txt":
      type = "text/plain";
      break;
     
    case ".doc":
    case ".rtf":
      type = "Application/msword";
      break;
    }
  }
  if ( forceDownload )
  {
    Response.AppendHeader( "content-disposition",
        "attachment; filename=" + name );
  }
  if ( type != "" )   
    Response.ContentType = type;
  Response.WriteFile( path );
  Response.End();    
}

The first few lines of code simply convert the file name argument into a physical path (on the server) and get the various component parts of the name. I only handle the file extension of known types that I'm currently using, but this could be extended to support additional MIME types (see the Microsoft article).

If the forceDownload boolean is true, I use the Response.AppendHeader method to add the "content-disposition" which forces the File Download (save) dialog.

I didn't find a lot of online help with the "content-disposition" header. In fact, it may even be on its way out in the future. But this currently works fine with IE 6 (and several prior version of IE upon which I've tested).

I recently found some posts on the ASPAlliance lists that also recommend setting Response.ContentType = "application/x-msdownload" to force the browser's download dialog. This should be especially useful when the type would otherwise be "application/octet-stream".

Visual Basic Example

Thanks to Mike Harber , I'm able to show the VB.NET version of the C# code example shown above. Thanks Mike.

Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
  Dim path As Path
  Dim fullpath = path.GetFullPath(fname)
  Dim name = path.GetFileName(fullpath)
  Dim ext = path.GetExtension(fullpath)
  Dim type As String = ""

  If Not IsDBNull(ext) Then
      ext = LCase(ext)
  End If

  Select Case ext
      Case ".htm", ".html"
          type = "text/HTML"
      Case ".txt"
          type = "text/plain"
      Case ".doc", ".rtf"
          type = "Application/msword"
      Case ".csv", ".xls"
          type = "Application/x-msexcel"
      Case Else
          type = "text/plain"
  End Select

  If (forceDownload) Then
      Response.AppendHeader("content-disposition", _
      "attachment; filename=" + name)
  End If
  If type <> "" Then
      Response.ContentType = type
  End If

  Response.WriteFile(fullpath)
  Response.End()

End Sub

Send your comments and let me know what you think of this article: steve@sharkcode.com

Steve Sharrock - www.SharkCode.com and www.AspAlliance.com/shark



User Comments

Title: ASP.Net   
Name: Shallinkumar Purohit
Date: 1/17/2013 4:08:02 AM
Comment:
How to open SaveDialogBox in ASP.Net
Please help me to solve this problem,
Title: Problem in Chrome   
Name: T
Date: 12/31/2012 3:04:39 AM
Comment:
HI, Does anyone know how to show the Save dialog in Chrome? it works fine in IE but does not show in chrome.
Title: ASP.NET   
Name: Manzer Rizvi
Date: 10/16/2012 9:46:07 AM
Comment:
TO - Website programmer who made this website..Sory to say but in below gridview,while commenting, today's time is displaying wrong.thx..
Title: ASP.NET   
Name: Manzer Rizvi
Date: 10/16/2012 9:42:15 AM
Comment:
This coding is just awesum..thx..
Title: asp.net   
Name: srinivasu
Date: 9/18/2012 1:16:25 PM
Comment:
In this program what i s path??????
Title: waste pages   
Name: vijayakumar
Date: 9/6/2012 2:05:27 AM
Comment:
Sorry, this type of code not working all .net application
Title: Thanks   
Name: Test
Date: 9/2/2012 5:13:21 AM
Comment:
Thank you so much.
This is really very helpful.
Once again thanks a lot.
Title: notification   
Name: sukhdev
Date: 5/7/2012 12:16:52 PM
Comment:
ok for using
Title: Mr   
Name: Suyog
Date: 4/30/2012 12:01:51 PM
Comment:
very good
Title: Mr   
Name: Tushr K
Date: 4/24/2012 3:38:39 AM
Comment:
very good article. It helps us.
Title: ok   
Name: viv
Date: 4/16/2012 6:01:51 AM
Comment:
ok
Title: Mr   
Name: Anurag
Date: 3/27/2012 4:22:54 AM
Comment:
Thanks a lot. This is really worth article and simple too.
Title: ebook downloading   
Name: anwar jamal
Date: 2/15/2012 6:00:35 AM
Comment:
it worked nicely for me, thank you for this article in public.
Title: code for download and upload songs and vedio in asp.net c#   
Name: Prashant
Date: 1/4/2012 8:07:20 AM
Comment:
please help me .
Title: When click on repiter button then get pdf for downloading   
Name: shaikh saber
Date: 12/1/2011 2:22:07 AM
Comment:
When click on repiter button then get pdf for downloading

thank you for this method but i want to that method
Title: automatic downloader   
Name: gandhi
Date: 11/5/2011 2:48:25 PM
Comment:
hello everyone .....i just want to know about the automatic downloader...when i pose the query to the google it should automatically download the pdf formatted files as well as the text typed files in to the specific folder....please send the idea about this program in what way i should do the project
Title: Website Designing   
Name: Adroit Web Solutions
Date: 10/17/2011 10:28:48 AM
Comment:
this is good programe for me. thanks
Title: download files in VB.net with Nhibernate   
Name: AiNa
Date: 10/17/2011 3:03:47 AM
Comment:
hi,
is there any sample of coding to download documents those we uploaded to the SQL server database. the project using VB.net, ASP.net framework and Nhibernate.
Title: How can implement Download Functionality Like Yahoo in Silverlight   
Name: Jayraj
Date: 10/10/2011 12:38:33 AM
Comment:
Hi,

I am trying to implement download functionality in Silverlight application, the functionality should be like same functionality provided by yahoo mail. Currently i have implement download functionality which have following features, 1. It read some byte from source and writes to destination. This process works till the last byte 2. Save dialog must appear before download. (And I am trying to bypass this save dialog box).
Please help me on this

Thank you
Title: helpfull   
Name: priya
Date: 9/28/2011 3:01:16 AM
Comment:
thanks... i can use this code in my project....
Title: Facing Issue while downloading large file using Silverlight and RIA service   
Name: Jayraj
Date: 9/28/2011 1:14:22 AM
Comment:
I am trying to implement functionality like download large file (Any Type e.g .docx, .pdf, .xlsx etc) in Silverlight application using RIA service.

Can anybody help me on this?
Title: MD   
Name: Juzer
Date: 9/1/2011 9:49:43 AM
Comment:
Great Concise Code
Title: Whispering after get this coding   
Name: S. Manna
Date: 8/5/2011 7:35:21 AM
Comment:
Hi Steve,

I am sukhen I am a developer of asp.net i like you amazing web site this is really great i hope your site live us many days on this planet.
Title: file download   
Name: baskaran
Date: 7/28/2011 10:57:30 AM
Comment:
It' s good but, we cant find submitbutton to download
Title: Display MS-Word Data on Webpage using .net   
Name: Dileep
Date: 7/25/2011 8:37:45 AM
Comment:
Hi Steve,
Is there way to display word data on to the Web page directly using MIME types? I cannot use word Interops as my servers do not have office installed and we dont have permissions to install them.

please reply me on my email dileeprajam@gmail.com
Title: Gam ka fasaana (hindi song)   
Name: down loaded in my documents
Date: 7/19/2011 4:56:55 AM
Comment:
the file didnot open for play
Title: Download file   
Name: Muralikrishna
Date: 7/18/2011 6:21:54 AM
Comment:
Excellent Article
Title: Very helpful   
Name: mike
Date: 7/11/2011 3:09:02 AM
Comment:
This tutorial is very helpful
Title: how clear fields when we sends data   
Name: vinodreddy.N
Date: 7/4/2011 6:40:17 AM
Comment:
hi,
I want to discribe the how to fields to the
Title: another vb.net version   
Name: mred
Date: 4/28/2011 9:34:38 AM
Comment:
this vb.net version works with all file types and explains some security risks:
http://it-things.com/index.php/2011/04/asp-net-force-file-download/
Title: Easier Approach   
Name: shawn souto
Date: 4/19/2011 3:05:01 PM
Comment:
Without putting too much though into this, can't you simply get the content type from the file? Similar to: http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html?
Title: doesn't download multiple files...   
Name: user1
Date: 2/15/2011 2:32:58 PM
Comment:
Hi,

On button cilck I save multilple files on server and when o try to download files using for loop it download one text file and rest of the file are not opening.

Is there anyway after saving file on server with path and file name I have to open all the saved text files.

Please help..
Title: Pls help   
Name: Faisal
Date: 2/3/2011 12:29:41 PM
Comment:
response.setContentType("application/x-download");
this code open a download window in the same window,as i am not able continue further(HTML)

I want open a new HTML window from current window whenever force download happens
Title: Error   
Name: Zeeshan
Date: 1/21/2011 11:13:46 AM
Comment:
I am getting error, I am using this code for downloadin a pdf file but it is saying "The message received from the server could not be parsed"
Title: Doubt   
Name: lunandam
Date: 1/10/2011 7:56:41 PM
Comment:
Hi, This code completely works for me. but I have a doubt. how can I get the path that user selected for the file???
please help me.

thank.
Title: Not working proprly with Chines character (Non-Ascii).   
Name: Subodh kumar
Date: 12/24/2010 3:46:25 AM
Comment:
I am facing issue with chinese character (Non-Ascii). And also, the attached file is not saved with the full file name. If file name has chineses characters then only 22 charaters are save with the file name.
Title: error while .pdf opening   
Name: Ajeet
Date: 12/23/2010 7:28:37 AM
Comment:
after downloading file in pdf format, it is not opening, showing error(file format not supported or file has been damaged
Title: Downloading Files - Forcing the File Download Dialog   
Name: SUNIL KUMAR SHARMA
Date: 12/14/2010 3:05:18 AM
Comment:
Thank you very much...................
Title: Need More Clariffication   
Name: Muthukrishnan
Date: 12/6/2010 4:14:41 AM
Comment:
hi stev,

how to track the user download the song?.(i.e)after the click save button how to update the status whether the user save the file or not?

Thanks
Title: thanks   
Name: Rev
Date: 12/5/2010 7:33:59 AM
Comment:
Cool Man
Title: Downloading Files - Forcing the File Download Dialog   
Name: balaji
Date: 12/1/2010 6:27:49 AM
Comment:
very nice.. really it worked great
Title: code for download and upload songs and vedio in asp.net c#   
Name: kaushal
Date: 11/30/2010 9:56:41 AM
Comment:
please help
Title: Force File Download   
Name: ariunaa
Date: 11/21/2010 10:14:32 PM
Comment:
Thank you very Much
Title: Force File Download   
Name: Amul
Date: 11/15/2010 11:24:31 PM
Comment:
Thanks for the Source Code. I was searching for this to download file which I was developing for the IntraNet Web Site.
Thank you very Much
Title: Force File Download Dialog   
Name: zessa
Date: 10/20/2010 9:28:50 AM
Comment:
Thank you very much. This helped me alot on my exam!
Title: Force download   
Name: Mindhe
Date: 9/28/2010 1:43:27 AM
Comment:
Thank you very much for your article. It helped me very much.
Title: Force Download   
Name: pbureau99
Date: 9/22/2010 4:39:41 PM
Comment:
EXACTLY what I was looking for. Thank you very much for this post.
Title: how to download files in asp.net c# code   
Name: rakeshgiri
Date: 9/17/2010 3:39:00 AM
Comment:
how to download files in asp.net c# code
Title: Download functionality   
Name: Pankaj chaurasiya
Date: 9/4/2010 10:45:45 AM
Comment:
please any one suggest me is this code run with dynamic button event.Thanks!
Title: good post but...   
Name: sunita
Date: 8/27/2010 7:21:23 AM
Comment:
hi,
nice code....
but i don`t want for open/save dialog box,instead contents should directly be displayed on web page.....so that not to allow for downloading.......
Title: How to download a file within Ajax controls   
Name: sowmya
Date: 8/2/2010 3:23:01 AM
Comment:
Hi,
I had a query. I wanted to know if there is any way to foce download a file which is present in sharepoint site?
The link to download this file is present within Ajax update pannels.
Now, when i click that link, I am getting the following exception:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Please can you help me out in this?
Title: Download   
Name: Murali
Date: 7/28/2010 3:23:14 AM
Comment:
I couldn't get correct output
Title: good   
Name: download
Date: 7/28/2010 3:20:52 AM
Comment:
good post
Title: Downloading Files   
Name: Vinay Sharma
Date: 7/21/2010 8:49:25 AM
Comment:
thank u very very much.. this code helped me very much...
once again thank u
Title: thanks   
Name: Amol
Date: 7/11/2010 10:21:34 AM
Comment:
Thanks 4 help
Title: C# example + Asp.net   
Name: RR
Date: 6/28/2010 9:04:02 PM
Comment:
Thank man worked like a charm
Title: Visual Basic Example   
Name: azam
Date: 6/23/2010 2:20:40 AM
Comment:
Thanks
Title: working code for file download using ASP.Net   
Name: SG
Date: 6/17/2010 12:59:09 PM
Comment:
Please find the working code for file download using ASP.Net

http://apachetechnology.net/knowledgecentre_swfiledw.aspx
Title: downloading from different server   
Name: katie
Date: 5/27/2010 4:23:13 PM
Comment:
has anyone ever made a download link that links to a file held on another server? i've made a couple of different download buttons and they both work when I link to my server, but whenever I link to the other server, it tries to download the php file instead of the mp3 file. not sure what the problem is
Title: Before open Html page dialog box save open cancel   
Name: Rohit
Date: 5/7/2010 11:58:05 AM
Comment:
Hi
I have developed teh page in ASP and changing the values in Html page after that i want same page before open dialog box required in ASP
Can someone help me....?
Title: document file upload & retrieve in sqlserver using asp.net with c#   
Name: sentamil murugan
Date: 5/5/2010 3:05:03 PM
Comment:
hi need to how do document file upload & retrieve in sqlserver using asp.net with c#
Title: Downloading a file on Right frame   
Name: Maran
Date: 4/6/2010 4:43:22 AM
Comment:
Hi i need to open the downloaded file on the right frame. How to open it. If i use "content-disposition" means it is opening on the new page.
Plz help me out.

Thanks in Advance
Title: writing and saving file   
Name: Naresh
Date: 3/29/2010 7:52:33 AM
Comment:
hello guys....i need to write a text file in asp using streamwriter and den save it on client machine ...what i need to do
Title: asp.net   
Name: hardik
Date: 3/23/2010 5:00:20 AM
Comment:
thanx.
Title: ASP.NET VB downloading word files   
Name: Rahul Pandya
Date: 3/21/2010 7:04:13 AM
Comment:
can u write whole code in asp.net with VB code to download file please...
thanks in advance
Title: Ajax + save file dialog box   
Name: Raj
Date: 3/19/2010 2:59:47 AM
Comment:
Response.ContentType = "File/doc";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName[fileName.Length - 1].ToString());

this code is not working with ajax. with ajax on my page, plz help me out
Title: Hi,   
Name: Nilesh Mohite & Vinod Kadam
Date: 3/3/2010 3:21:31 PM
Comment:
Thanks, dude !

Nice job !

Nilesh
Title: Error   
Name: Sohaib
Date: 3/2/2010 7:50:27 AM
Comment:
Hi this is an helpful post
But i am getting Exception when i reached "Response.End()".
Can anyone tell me the solution. I am stuck and in hurry

Any little help will be greatly appreciated.
Thanks in advance

Regards
Sohaib Qazi
Title: Mger of Admin Tech   
Name: Dan Lubbs
Date: 2/25/2010 11:24:01 AM
Comment:
I had a similar case. Two asp pages on same server & both create an xls file. One worked, one didn't. Most of my asp pages start with
<% Response.ExpiresAbsolute = #1999-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, nocache, must-revalidate" %>
to force a refresh each time the page is displayed.

DON'T DO THIS IF YOU ARE CREATING an xls display.
Title: Ajax and download   
Name: iStan
Date: 2/12/2010 5:34:38 AM
Comment:
@Farid Haddadin
Sure it works with AsyncPostback, but the button that triggers the event needs to be set as a PostBackTrigger in your updatepanel.

Something like: Triggers
asp:PostBackTrigger ControlID="Button1"/
/Triggers
Title: the dialog keeps poping up   
Name: Farid Haddadin
Date: 1/27/2010 1:57:21 PM
Comment:
The code work fine, with two problem:
1- the dialog keeps poping up when I ever press any another button in the page.

2- this code is not working with ajax ASP.

Is there any idea to solve the above problems.
Title: Saving File   
Name: Nick
Date: 1/19/2010 11:02:38 AM
Comment:
This works great, just what I was looking for. I appreciate the VB conversion as well.

Cheers,

Nick
Title: Downloading a file   
Name: David - Chennai
Date: 1/14/2010 4:47:00 AM
Comment:
Thanks steve. I have resolved all my bugs through this article and my download page is working fine.
Title: Downloading a file   
Name: srikanth
Date: 12/22/2009 7:11:56 AM
Comment:
Hey,
Really great dude i struggled a lot,your code helps me and saves my time. Thank You very much!
Title: Removing File Type : All from the list of file types   
Name: redb
Date: 12/21/2009 12:44:07 AM
Comment:
HI,

Can i make my save as dialog box to only save as pdf files... as in only pdf files and the FILE TYPE: ALL is not listed in the file type only .pdf!

thanks,
redb
Title: Downloading a file   
Name: Joyal
Date: 12/13/2009 9:53:59 PM
Comment:
Ok now go down to the BNL Cursor and there is a click here to download option try it and can anyone send me an HTML for that? I tried viewing it in page source but I couldn't find it. I am only 15.. please help. I need HTML
e-mail:- runescape632@gmail.com
Title: Downloading a file   
Name: Joyal
Date: 12/13/2009 9:46:20 PM
Comment:
Html version of this code u had:


private void DownloadFile( string fname, bool forceDownload )
{
string path = MapPath( fname );
string name = Path.GetFileName( path );
string ext = Path.GetExtension( path );
string type = "";
// set known types based on file extension
if ( ext != null )
{
switch( ext.ToLower() )
{
case ".htm":
case ".html":
type = "text/HTML";
break;

case ".txt":
type = "text/plain";
break;

case ".doc":
case ".rtf":
type = "Application/msword";
break;
}
}
if ( forceDownload )
{
Response.AppendHeader( "content-disposition",
"attachment; filename=" + name );
}
if ( type != "" )
Response.ContentType = type;
Response.WriteFile( path );
Response.End();
}
Title: Downloading a file   
Name: Joyal
Date: 12/13/2009 9:44:27 PM
Comment:
Hey I need help with putting a click here to download (file name) option for my website. It needs to be html. you put like an image link then you click the thing then it will download. like when you download a game in your computer like that option. please reply to me with an html code on my e-mail
runesape632@gmail.com
Title: DownloadFile VB.NET   
Name: Sathish
Date: 11/11/2009 7:57:29 AM
Comment:
This article is very useful. Explains the code in simpler manner and easy to understand. Thank u
Title: DownloadFile VB.NET   
Name: Filippo Franchini
Date: 10/6/2009 12:07:33 PM
Comment:
Great! Very useful, thanks a lot!

Hope it'll keep on working even with future releases of IE.
Title: thnx   
Name: abc
Date: 9/8/2009 2:05:10 PM
Comment:
Thanks..
this helped me.
Title: I need a reverse!   
Name: Ahmed Sprouse
Date: 9/7/2009 2:40:54 AM
Comment:
Hello..
I need a code that make any browser to display a (hta) file directly without asking for download.
Thanks previously.
Title: need for my requirement   
Name: devi
Date: 8/19/2009 6:44:00 AM
Comment:
need the coding for download i.e,it will be save button and open button in dialog box
Title: This works   
Name: VK
Date: 8/18/2009 11:52:55 PM
Comment:
Thank You so much.

It worked !!!
Title: thanks a lot   
Name: Rinki
Date: 7/31/2009 2:02:46 AM
Comment:
This was very helpful for me. thnx a lot.
Title: Thanks   
Name: Jérôme
Date: 6/29/2009 9:44:10 AM
Comment:
Hi!
Thanks a lot for your article. It helped me a lot.
Title: RE: Downloading Files - Forcing the File Download Dialog   
Name: Zain Shaikh
Date: 6/13/2009 1:35:01 PM
Comment:
how can i download the file from any other site?
Title: Need For My Requirement   
Name: Dorababu
Date: 6/11/2009 11:06:43 AM
Comment:
Hi good article. But i need the same for my requirement can any one help. I am displaying the data in a grid view as follows..

Name Filename
Dora abc.doc
Sai Xyz.pdf
xyz abc.txt

All these file names are displayed as link buttons what i need is when i click on those file name i would like to get a pop window as open save and cancel. The files i saved are directly saved in to SQL. So can any one help me regarding my requirement please its very urgent to me.

Thanks in Advance
Title: thanks : )   
Name: mary
Date: 5/12/2009 4:32:30 AM
Comment:
it is exactly that i want....
Title: file download dialog click status   
Name: kishore
Date: 5/11/2009 1:21:22 AM
Comment:
I have 1 question how to know where the user click (on OPEN, SAVE or CANCEL) button of file download dialog box. How we handle the events for 'File Download' popup.

Waitting for Reply...

If you have any idea on this please send me reply to following address.

ckishore@stcroixsystems.com
Title: Error   
Name: Shyam Sundar.S
Date: 4/30/2009 9:50:57 AM
Comment:
While Useing this Code if you will get any Error-->
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Hi My friend

just put this code before of the final catch statement (Before Exception catch)

catch (System.Threading.ThreadAbortException lException)
{

// do nothing

}
Title: hey thanks alot   
Name: anon
Date: 4/23/2009 11:46:35 AM
Comment:
This worked Great!
Title: No Dialog   
Name: Chris
Date: 4/16/2009 12:30:14 PM
Comment:
I have the code that will download a file but the dialog keeps poping up. I want to download a file to a specific local directory without any dialogs. is it possible?
Title: Get return value of button   
Name: Vimal pakur wale(vimal_bca@yahoo.co.in)
Date: 3/18/2009 8:02:57 AM
Comment:
I need to get the return value of button so that I do further. If user click on save button then I need to update file but when user click on open button then there is no need to update any file.
Please help me if it is possible.
thanks in advance
Title: perfect   
Name: coskun
Date: 2/6/2009 10:19:15 AM
Comment:
hi, my man this is a perfect article.
thanks.
Title: Downloading Files - Forcing the File Download Dialog   
Name: DaniBoi
Date: 1/20/2009 4:55:49 AM
Comment:
how to do it in .net 1.1?
Title: code after force downloaded the .txt file doen't work   
Name: Balu
Date: 1/16/2009 12:59:43 AM
Comment:
Hi, thanks for code. my requirement is once i force download .txt file(example: after save the file to desktop), my client wants to display the successfully downloaded msg panel.but the code after
If (forceDownload) Then
Response.AppendHeader("content-disposition", _
"attachment; filename=" + name)
End If
If type <> "" Then
Response.ContentType = type
End If

Response.WriteFile(fullpath)
Response.End()


is not working... how can i make it work to display successfully downloaded msg?
Title: how to avoid download dialog   
Name: Usman Lakhani
Date: 1/9/2009 9:44:08 AM
Comment:
Thank you for putting this code online. Its very helpful.
However is it possible to by pass the download dialog box. we are trying to automate the download of a file from a server but the download dialog box keeps us from doing that
Title: Thank you   
Name: Lalla Zaîneb
Date: 12/25/2008 12:25:42 PM
Comment:
Hi there !
thank you , that was very very useful
for me,it worked wonderfully
Title: Downloading files directly from free file hosting services   
Name: Irfan
Date: 12/20/2008 3:21:29 PM
Comment:
Dear sir,
I created a blog in which i putup some pdf files with their respective dowloading links beneath them.These link direct to the site where i have stored my pdf files.Can you tell me please, how can i download any particular file from my blog itself directly, without having redirected to the site where that file is stored.
Title: Ajax + File download dialogue box   
Name: Xap
Date: 11/26/2008 4:22:03 AM
Comment:
this code is not working with ajax. with ajax on my page, i want a link to download the file.

plz help!
Title: Allow a folder to be downloaded   
Name: sadananda
Date: 11/21/2008 2:08:04 AM
Comment:
i want a folder to be downloaded not a single file...how can i do that..

waiting for reply
Title: Remaining code does not execute   
Name: kalaravi
Date: 11/17/2008 8:39:34 AM
Comment:
Hi guys,

This code works good. but if i write any other code after execution of this code in the same method. that does not reflect.

Per say, I've disabled a serverside button before or after executing the download operation. that is not happening...

This is a serious problem for me....

Please help me out.....

Please send your suggestions to kalaravi@verinon.co.in
Title: steve@sharkcode.com   
Name: Laxmi
Date: 10/23/2008 12:45:48 PM
Comment:
Thanks it worked for me. Only difference is I used Response.TransmitFile.
Title: FileUpload   
Name: File
Date: 10/18/2008 4:56:29 AM
Comment:
Good
Title: Help Needed   
Name: Pankaj
Date: 10/7/2008 2:18:31 AM
Comment:
Very Nice Post.
Title: Help Needed   
Name: Omer Farook
Date: 9/9/2008 3:43:32 AM
Comment:
Nice Post, but i want to download from FTP location otherthan webserver location, please rep me
Title: Very usefull   
Name: Fabio Mastaler
Date: 8/23/2008 1:12:33 PM
Comment:
Thank you very very very much
Title: Good Help   
Name: Juan
Date: 5/5/2008 10:57:43 AM
Comment:
I have 1 question how one can know where the user click (on OPEN, SAVE or CANCEL) button of file download dialog box. How we handle the events for 'File Download' popup.

Waitting for Reply...

Juan
elavee@gmail.com
Title: Save Success   
Name: Elizanna
Date: 4/15/2008 8:23:08 AM
Comment:
As simple as. Worked successfully!
Thanks.
Title: Save Dialog box not working in IE6   
Name: Ganesan S
Date: 4/11/2008 1:51:20 AM
Comment:
Your code is working fine with IE7 and Mozilla, but it's not working in IE6. Please guide me.
Title: download mp3 song   
Name: pravin
Date: 4/1/2008 4:47:40 AM
Comment:
i want to design song download website in asp.net.
i store the path of the song in the database,when user select song ,the download window should open saying where to download on pc and then progress window




can anybody help me .........
Title: Down load   
Name: sunil
Date: 3/25/2008 7:24:23 AM
Comment:
i used the above source code for down load .pdf file.
but i got an error- "ex = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}"
what can i do for this problem
Title: About Open/Save   
Name: Hameed
Date: 3/18/2008 3:15:46 AM
Comment:
I cant able to open the file which has opened through open/save dialog box why? I want to know the reason

Regards
Hameed
Title: Extrodinory   
Name: Ravikumar
Date: 3/1/2008 6:21:58 AM
Comment:
thank you
your article was very usefull and i need to get the file path from the user by the filedialog
Title: Good Stuff   
Name: Balaji
Date: 2/25/2008 6:13:10 AM
Comment:
It is a very good article. It helped me a lot in crossing a hurdle, which i was facing in my project.
Title: Good Help   
Name: Rakesh Bhavsar
Date: 2/14/2008 4:18:38 AM
Comment:
Hi! guys
This is a very nice help for opening any type of file in browser or into the content type editor.
I have 1 question how one can know where the user click (on OPEN, SAVE or CANCEL) button of file download dialog box. How we handle the events for 'File Download' popup.

Waitting for Reply...
Rakesh
rakeshnb@mechsoftgroup.com
(INDIA)
Title: Downloading Time   
Name: Vignesh
Date: 2/11/2008 11:30:17 PM
Comment:
Hai, While downloading, if the time exceeds to download takes more than 10min, it should automatically stops downloading with error message. How to implement this.. Can any help???
Title: Problem with firefox   
Name: sudha
Date: 1/23/2008 3:17:28 AM
Comment:
Great article - very useful - but in Firefox, the save dialog opens, and it saves the file but without a file extension! It works great in IE. Any suggestions on how to fix this?
awaiting..
send ur reply @
rathi.sudha13@gmail.com
Title: Thanks   
Name: Chloe
Date: 12/13/2007 4:10:36 AM
Comment:
When I tried it with the VB.NET code I had a number of warnings etc.
Other than this it was very helpful.

Here is the code which did not create any warnings.

Private Sub DownloadFile(ByVal strPathFile As String, ByVal bForceDownload As Boolean)
Dim strPath, strFileName, strExt, strType As String

strPath = System.IO.Path.GetFullPath(strPathFile)
strFileName = System.IO.Path.GetFileName(strPath)
strExt = System.IO.Path.GetExtension(strPath)

If Not IsDBNull(strExt) Then strExt = LCase(strExt)

Select Case strExt
Case ".htm", ".html" : strType = "text/HTML"
Case ".txt" : strType = "text/plain"
Case ".doc", ".rtf" : strType = "Application/msword"
Case ".csv", ".xls" : strType = "Application/x-msexcel"
Case Else : strType = "text/plain"
End Select

If bForceDownload Then Response.AppendHeader("content-disposition", "attachment; filename=" + strFileName)
If strType <> "" Then Response.ContentType = strType

Response.WriteFile(strPath)
Response.End()

End Sub
Title: Working in Callback?   
Name: Suresh
Date: 12/11/2007 1:23:24 AM
Comment:
Hi,

Is it working in asyncronous postback?

Might be silly. But details would be great help!

Thanks,
Suresh.
Title: Download file on postback: Firefox problem   
Name: Andres
Date: 12/3/2007 7:24:06 AM
Comment:
Hi all,
I have a page (C# ASP.NET) with a link button which when clicked, executes a postback that downloads a file for the user. The way this file is downloaded is:

1.
FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath(filena me));
2.
if (file.Exists)
3.
{
4.
HttpContext.Current.Response.Clear();
5.
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
6.
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
7.

8.
HttpContext.Current.Response.ContentType = Constants.MimeTypes.Excel;
9.

10.
HttpContext.Current.Response.BufferOutput = true;
11.
HttpContext.Current.Response.WriteFile(file.FullNa me);
12.
HttpContext.Current.Response.End();
13.
}



This works perfectly under IE7, but in Firefox it only works the first time, all subsequent postbacks (downloads or any other postback) is ignored and nothing happens. I guess it must be messing something up in the headers, but can't figure out what's wrong. Any ideas?
If similar code is executed upon url request (ie http://mywebsite/getfile.aspx?id=3) then it works fine, seems it's only when done in a postback.

Thanks very much
Title: Error as Script Time Out.   
Name: Yatish Shah
Date: 11/13/2007 7:50:44 AM
Comment:
While downloading xl sheet from asp pages i am getting following error:
Script Time Out.

I have increased the Script Time Out number.
But still getting the same error.
Should i increase the Download option of Excel sheet from by default 4mb to more. How can i do this?
Please help.
Title: Downloading Files - Forcing the File Download Dialog   
Name: Arvind
Date: 11/2/2007 5:55:29 AM
Comment:
Need more in detail.
Title: IE 6.0 problem - answer...   
Name: Leo
Date: 10/25/2007 10:23:57 AM
Comment:
Response.ContentType = zstrContentType
Response.AppendHeader("Content-Length", zlngFileSize)
'Setting sort of encoding
Response.AppendHeader("Content-Transfer-Encoding", "binary")
Response.AppendHeader("Content-disposition", String.Format("attachment; filename=""{0}""", pstrFileName))
Response.Expires = 0
Response.AppendHeader("Pragma", "cache")
Response.AppendHeader("Cache-control", "private")

This code works perfect in IE 6 (SP2) and IE 7 as well as mozilla browsers. Although it does not work with IE 6 (SP1).
Title: IE 6.0 problem   
Name: Leo
Date: 10/25/2007 9:33:49 AM
Comment:
Same issuse... This code works in all browsers except for IE 6. Can you please help me?.

Response.ContentType = zstrContentType Response.AppendHeader("Content-disposition", String.Format("attachment; filename=""{0}""", pstrFileName))
Response.AppendHeader("Pragma", "public")
Response.AppendHeader("Cache-control", "must-revalidate")

lozano.leonardo@yahoo.com
Title: urgent requirement   
Name: P.Naresh
Date: 10/24/2007 2:07:04 AM
Comment:
Hi
I need this urgently, can any one help me.I need to open a word document from browser which i am doing successfully, but how can i edit it and save it in the same location without prompt dialog, the document is opening in readonly mode.i am using PHP.
Kindly send me the source for this.
Thanks
Title: Excellent work   
Name: bala_tv
Date: 10/16/2007 3:21:29 AM
Comment:
thanks

This is solve my problems
Title: problem with OPEN button   
Name: Mamta
Date: 8/28/2007 3:31:08 AM
Comment:
the "OPEN" button is not opening the file in IE 6.0.Can you please tell y is it happening like that? my email id is mamta.melwani@hcl.in;
Title: need help: urgent   
Name: Meenakshi
Date: 7/27/2007 3:12:38 AM
Comment:
Cord worked very fine. Was able to save it on my local machine. I need to retrieve the values of aspx page(from where the save dialog was opened) onto word doc before saving..
can also be contacted on meenakshi@marineinfratech.com
Title: Downloading a file from sub root folder   
Name: Naveen Kumar Koppera...mumbai
Date: 7/11/2007 10:22:05 AM
Comment:
Hi ,
This code works well but only at root level.ie Appliaction Root.but i want to use Application root/folder level.
i tried to this but you are using relative path.so plz help me how should i download file from subroot level folder
Title: Problems while downloading the PDF files from site   
Name: Avadhut
Date: 7/5/2007 2:14:28 AM
Comment:
Hi All,

I have an application which is used to publish some PDF documents and user (available thru web) will be either opening them for viewing purpose or will save them and then open it.

Recently i added 'content-disposition' header with an intention of providing a proper file name at the time of saving the file.

Now the new problem that i m facing is that when i clik on the document link for some of the PDF files i get 'File Download' dialog box. If i click on 'Open' button it opens it in new Acrobat Window. I m not sure why this change in behavior is thr. This dialog box comes only with IE and not with Firefox.

Also one more observation is that this dialog box comes mostly for PDF files which i have uploaded by downloading from the internet.

If any body has any suggestion's on how to get rid of this 'File Download' dialog box..pls do write.

Advanced Thanks,
Avadhut.
Title: Needs to save the document without prompt   
Name: prashanth
Date: 6/8/2007 7:34:50 AM
Comment:
Hi
I need to open a word document from browser which i am doing successfully, but how can i edit it and save it in the same location without prompt dialog, the document is opening in readonly mode.
Kindly send me the source for this.
Thanks

Prashanth.N
prashanthkumar.n@tcs.com
Title: Not allowing "." in the file name to be downloaded.   
Name: Sajid
Date: 6/5/2007 7:08:18 AM
Comment:
Hi,

Let say i have the code
...
...
1. Response.ContentType = "Application/txt";
2. string FilePath = MapPath("file.txt");
3. Response.AddHeader("Content-Disposition", "attachment; filename=" + "file.txt");
4. Response.WriteFile(FilePath);
5. Response.End();

With this code i can download the file "file.txt";

If i would like to save the file as "file.abc.txt" how can we do it.

I tried with the following code
3. Response.AddHeader("Content-Disposition", "attachment; filename=" + "file.abc.txt");

I can able to download the file but the file name is
"file[1].abc.txt". How can i restrict the "[1]" subscript from the file name.

Please send me your suggessions @: mmsajid@gmail.com

Thanks
Sajid
Title: Mr   
Name: Duc Dinh Nguyen
Date: 5/18/2007 7:38:22 AM
Comment:
Thank you very much.
I am having some problem in this subject.
You are great!
Title: avoid the Filedownload dialog Box   
Name: Dhinesh
Date: 5/14/2007 5:13:28 AM
Comment:
I want to avoid the Filedownload dialog Box before download the CSV file,Please any one helf me. i am using PHP
Title: Forcing the Filedownload dialog   
Name: Raja
Date: 4/29/2007 10:10:40 AM
Comment:
Hi,
This code saved me almost a day. Thanks for the code buddy.
Title: how to avoid file download popup   
Name: Mani
Date: 4/27/2007 8:49:19 AM
Comment:
In my user screen I have view link, if I click this link it will go to servlet and open one word document. It is opening properly, but while opening the attachment it generate one dialog box like file Open, Save or Cancel button, if I click open after that it is opening the document. But my query is it should not display this dialog box, once I click the link it should open the document automatically using HttpServletResponse. Can any one help me to avoid the pop up window?


Sample Code

// Header (file name) is coming and file download pop-up also coming for below code

response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename=testing.doc");

// File name is not coming and file download pop-up also notcoming for below code

response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=testing.doc");

Please any one can help me?
Title: Thanks   
Name: Reinoud
Date: 4/27/2007 4:47:49 AM
Comment:
Nice one! Easy to use... thanks for the effort
Title: open PDF file within browser with asp.net/c#   
Name: anil sahu
Date: 3/30/2007 6:57:35 AM
Comment:
hi dear..
can any 1 help me ...
how can we browse PDF file ?
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/doc";
try
{
Response.WriteFile(Server.MapPath("/Hammocks/Hammock_Image/aspnet-sample.pdf"));
//Response.WriteFile( MapPath( "" +Request.Params["File"].ToString() ) );
Response.Flush();
Response.Close();
}
catch
{
Response.ClearContent();
}
i have used ..but here SAVE as option is there is there..
means user can read it but don't save ..
how can we do this. hel pm.... ASP
thx in advance
Title: good   
Name: i w'll try it
Date: 3/17/2007 7:53:06 AM
Comment:
thank your effort
Title: very useful for me   
Name: ZweThiHa
Date: 3/12/2007 4:39:03 AM
Comment:
very useful for me... thz GIGA
Title: Need to disable a button after download   
Name: Ahm
Date: 3/7/2007 3:03:20 PM
Comment:
Hi, Nice article, but when I say button1.enabled = true after/before response.end(), it is not working.

Do you have any example that shows button enabling/disabling with response.end()?
Title: Viewing a report in PDF or excel in the browser   
Name: Trupthi
Date: 2/25/2007 3:57:01 AM
Comment:
In my application i when the user clicks a button, the report generated should open up in PDF or excel format in the browser window itself without bringing up the dialog box to open or save the file first.

Please let me know how this is done.
Title: Downloading Files -- Forcing the Download Page   
Name: Aaron
Date: 2/21/2007 12:00:19 PM
Comment:
This does not seem to work on with a Windows2003 server with SP1 installed. How can I make it work?
Title: Mr   
Name: Phillip Knezevich
Date: 1/30/2007 12:14:29 PM
Comment:
Great article, not much around about this on MSDN - quick and easy to use, well done.
Title: downloadfile   
Name: mc
Date: 1/24/2007 4:44:49 AM
Comment:
i was hunting for the download file code for almost a month. thanks to u, i've got wat i wanted.
Title: Down Load File   
Name: Bhushan Deo
Date: 1/16/2007 12:12:30 AM
Comment:
The article is good but when we use Windwos2003 Server and Thin Client node the dowload process doesn't run we face that problem. But when we run same project on server it runs properly. Please give me answer. My email id is
deo_bhushan@yahoo.com
Title: uregent:Two dialogues are opening when using this code   
Name: Lakshmi
Date: 12/22/2006 3:40:42 AM
Comment:
If i use the below code to download the xl sheet format, it is showing two dialogue boxes instead of one

Response.ContentType=Response.AppHeader("content-disposition","attachement;filename="+name);
Response.contentType="Application/vn.ms-excel";
Response.WriteFile(path);
Response.End();


Can you help me on this context

Regards,
Lakshmi
Title: Amazing Article....!!!!   
Name: Asif Ali from Indore, India.
Date: 12/22/2006 2:56:47 AM
Comment:
Great Job Steve Sharrock,

Thanks,
Asif Ali (contactasifali@gmail.com)
Title: some additional features !   
Name: Freddie
Date: 11/30/2006 11:47:13 PM
Comment:
Hi everybody ! great article. i just saw this example about downloading a file/report, that creates the downloadable data 'on the fly', which means that the file is never stored anywhere on the server. The only place it's written to disk, is at the end user's computer.
This means you never have to manage any files, or worry about having your files stored in a secure place etc.
It's available at:

http://www.realistic-code-samples.com/CodeViewer.aspx?projectid=8

It shows the code, provides a live demo and source code download etc...

keep up the good work guys :-)
Title: simply gr8   
Name: Fahad
Date: 11/15/2006 3:10:42 PM
Comment:
Brilliant stuff, keep posting...
Title: Download Dialog in Web Application   
Name: sachin from Mumbai
Date: 8/28/2006 9:11:51 AM
Comment:
I want a method that how to display the file download dialog(Save) in Web Application using ASP.NET 2.0?Because on my application file size is unlimited.My application for FTP.File comes from FTP.I have stuck on how to display the download dialog(save) on client machine, and file size is unlimited.
Please help.
Title: Downloading Files   
Name: Saravan Pandian. P(Melss Automation Ltd)
Date: 8/26/2006 3:34:08 AM
Comment:
this artical very supper. realy it is very helpful for me.
i done succfully.

Thanks & Ragards
Title: Problem of "open" in IE   
Name: vijesh
Date: 8/11/2006 5:37:31 AM
Comment:
This code completely works for me. But there is problem the "OPEN" button is not opening the file in IE 6.0 but it works smoothly for mozilla (fire fox) can you just say what is going wrong with IE. My email address is jay_vijesh@rediffmail.com
Please do send reply for this.
Thanks
vijesh
Title: very nice   
Name: sreekanthreddy kurri
Date: 7/27/2006 7:09:52 AM
Comment:
it is simply super ,& thanks
Title: Remote files   
Name: Ihab El-Kabary
Date: 7/8/2006 8:13:45 AM
Comment:
Excellent article,

I have a problem though, I need to force the SaveFile dialog to download content that is "NOT" on my server. In other words, the files to be downloaded are on other servers.

This code doesnloads only few bytes of files then terminates!

Any ideas??

THANKS

my email is:
ihabmc18@hotmail.com
Title: Mr   
Name: Guillaume
Date: 7/5/2006 9:14:45 AM
Comment:
good code, but I had to change path.GetFullPath(fname) to server.MapPath in order to make everything work with my pages.
Title: File Download Dailg Box   
Name: Preethi Rajesh
Date: 6/6/2006 3:01:11 AM
Comment:
Excellent article, perfect content for file downloading

Thanks
Title: source code to convert ECG text data to dicom format   
Name: awad bakr
Date: 5/14/2006 6:49:41 AM
Comment:
i want source code to convert ECG text data to dicom format
Title: Downloading Files from a Popup window, it itself get closed   
Name: Kirti
Date: 4/25/2006 2:37:27 AM
Comment:
I m trying to download the files from the popup window. it shows me open, save & cncel button. but when I click on cancel. it closes the popup window. I fcaed this issue only on XP. it works fine on win2k/NT.

Please help me out.I m pulling hair out because of this.
Title: Good Article   
Name: Prenesh Seethal (South Africa)
Date: 4/13/2006 4:44:34 AM
Comment:
Is a very good article but entire code should be made available
Title: Mr   
Name: Prenesh
Date: 4/13/2006 4:42:16 AM
Comment:
Is a very good article but entire code should be made available
Title: Solution is Not Working   
Name: Chandan
Date: 4/8/2006 12:30:43 AM
Comment:
Dear Sir,
I want to give option of attachment downloading to user. for that i have to show user file download dialog box how to do that?

waiting for reply
chandan
Title: Nice and easy   
Name: Marcus Pereira
Date: 4/7/2006 9:57:37 AM
Comment:
It was nice to see an easy "how-to" about this issue. I was not interested in wasting my time with this issue, and this article was exactly what I want.
Title: Download File of any Type   
Name: Dilip Singh Bat
Date: 4/7/2006 3:21:52 AM
Comment:
I got the exact solution what i am searching for. It is really simple and short solution. I like this article very much. But Can we build our own window instead of micresoft window.
Title: Save as Dialog   
Name: George Stylli London
Date: 3/31/2006 2:51:42 AM
Comment:
Thanks for the code, searched high and low for this one. Really pleased to get it working.

Thanks for your efforts!!!
Title: Outstanding   
Name: Dean Colcott
Date: 3/21/2006 7:06:50 PM
Comment:
Hi Steve / Mike,

One area not covered was the usefulness this simple few lines of code is in adding security. By setting the file path to a Secure Path (Outside the virtual directory) and having a Adding a key under AppSettings of the web.config you can allow users to download files from a NTFS secured area (Using either the LocalServices or ASPNET user).

Compared to adding a direct link to the file which is not an option when (as in most cases) the download directory is shared by more than one user. In this example use ASP.NET authentication and roles to grant access to the front end and keep your files out of expensive binary store as in SQL / MySQL.

Great work guys. You saved me many headaches.

Regards,

Dean.
Title: Downloading Files - Forcing the File Download Dialog   
Name: ganesh
Date: 2/22/2006 7:24:08 AM
Comment:
This article looks good, but I want to export image file(.jpg) into msword,excel and html.But it was not exporting.
Image file is in server system.
Title: Downloading without dialog   
Name: Roopa
Date: 1/27/2006 8:18:44 AM
Comment:
Can i download a file without prompting the user to save or open the file
Title: How to avoid save file dialog box   
Name: Gary
Date: 1/24/2006 12:09:53 AM
Comment:
How to avoid save file dialog box when i need to save a file automatically?
Title: forcing download dialog box   
Name: captain sportster
Date: 1/14/2006 10:33:28 AM
Comment:
This is exactly what I want to do but I don't want to (can't) use and ASP page. Is there a way to accomplkish this using Javascript in an html page?
Title: Amernath   
Name: Amernath
Date: 9/9/2005 3:09:45 AM
Comment:
Grt code. We even tried out executing it from a popup and it came out successful. Pu an iFrame in the popup and perform the action from it. The iFrame ought to be invisible.This does the trick.
Title: [Continued....]csv files gets appended with .aspx extension in netscape   
Name: Aseem
Date: 9/1/2005 7:09:39 AM
Comment:
context.Response.AddHeader("content-disposition", "attachment;filename=" & fname)
End If
context.Response.BinaryWrite(byteArray)
context.Response.Flush()
context.Response.End()
End If
Catch ex As Exception
Select Case ex.Message
Case "Thread was being aborted."
'do nothing aborted by Response.End()
Case Else
Server.Transfer("error.aspx")
End Select
End Try
****************************

Please let me know how can i avoid getting the ".aspx" appended to the .csv file.
Regards
Aseem
End Sub
Title: csv files gets appended with .aspx extension in netscape   
Name: Aseem
Date: 9/1/2005 7:04:13 AM
Comment:
I am using the following function to download a csv file, but the open file dialog in NS 7.0/7.1 (on win 2k/xp) appends .aspx extension to the file.

*************************************

Public Sub DownloadFile(ByVal fs As MemoryStream, ByVal fname As String, ByVal FileExt As String, ByVal forceDownload As Boolean)

Try

Dim type As String = ""
Select Case FileExt
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
'type = "Application/x-msexcel"
type = "text/csv"
Case Else
type = "application/octet-stream"
End Select

If (forceDownload) Then
Dim objCaps As New HttpBrowserCapabilities
objCaps = context.Request.Browser
Dim byteArray As Byte() = fs.ToArray()
context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.Expires = 0

If objCaps.Browser = "IE" Then
'Checked if OS is WIN XP or MacPC then download as attachment
If UCase(objCaps.Platform.ToString) = UCase("WINXP") Or objCaps.Platform.ToString.StartsWith("M") Then
context.Response.ContentType = type
context.Response.AddHeader("content-disposition", "attachment;filename=" & fname)
Else
context.Response.ContentType = type
context.Response.AddHeader("content-disposition", "inline;filename=" & fname)
End If
Else
context.Response.ContentType = type
context.Response.AddHeader("content-dispositi
Title: Uploading Files   
Name: Ramasamy
Date: 8/30/2005 10:16:20 AM
Comment:
I need a coding in asp.net for uploading a folder to Server.
Let it be clear . I have a button when i click the button i need to ask for browsing a folder in client machine(Folder browser should open not file Browser). If i select a Folder path all the folder files should save in Some Static path directory in Server machine..
Can u please send this coding to me...

please send the response to
ramasamy.p@gmail.com
Title: On-demand PDF creation and download issue   
Name: Michael Yuan
Date: 6/29/2005 11:30:26 AM
Comment:
Hi did anyone find a solution to Girish Nair's problem? i'm interested in the solution, if so you can email me at myuan@anl.com thanks .
Title: very useful article   
Name: Neelesh Arora employee of, www.bbspl.com
Date: 6/21/2005 4:21:29 AM
Comment:
thanks a lot for this code, it helps me to sort out the very big problem. Thanks
Title: How to open/save two files from web server on single click event   
Name: Pinkesh Dalal
Date: 5/27/2005 1:07:25 AM
Comment:
This solution is really good. It helped me to open/save file in asp.net.
Actually i m dealing with images of .bmp and .dcm (DICOM)
I have some other requirement like

"How to open/save two files from web server on single click event in same/different instances of viewer"

I have tried following code but it is opening first file only :
Response.ContentType = "application/x-msdownload"
Response.AddHeader("content-disposition", "attachment; filename=" + filename)
Response.WriteFile(url)

Response.ContentType = "application/x-msdownload"
Response.AddHeader("content-disposition", "attachment; filename=" + filename1)
Response.WriteFile(url1)

Response.flush()
Response.end()

Please be needful for this
Title: On-demand PDF creation and download issue   
Name: Girish Nair
Date: 4/25/2005 12:44:56 PM
Comment:
Sorry, part of the code didn't make it last time. Looks like there is a limit.
private void ExportReport(string strReportId, string strFormatId)
{
Response.Clear();
Response.ClearContent();
Response.BufferOutput = true;
Response.Buffer = true;
int iReportId = Convert.ToInt32(strReportId);
Report selReport = m_RFManager.GetReport(iReportId);
if (selReport == null)
{
Response.End();
}

// Let's start with letting the client(browser) know that we are in the
// process of a file download. This is needed because the report
// generation can take a while and we don't want the user to
// wait for the file download dialog.
string strFileExtension = m_RFManager.GetExportFormatFileExtension(strFormatId);
Response.ContentType = "application/x-download";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + selReport.Name + "."
+ strFileExtension);
Response.Flush();

// Now generate the actual report and send to the client(browser)
byte[] report = m_RFManager.ExportReport(
strReportId,
strFormatId,
ref strFileExtension);

Response.BinaryWrite(report);
Response.Flush();
Response.Close();
// Response.End();
}
Title: On-demand PDF creation and download issue   
Name: Girish Nair
Date: 4/25/2005 12:42:17 PM
Comment:
Folks, I'm struggling with the below issue:
I'm working on the export mechanism for reports dynamically (on-demand) generated using MS SQL Server Reporting Services.
- User via the web interface clicks a button to export to PDF
- My code asks reporting services to create the report in PDF format
- Once the reporting services call (Render() method) returns I write the report as binary to the Response object.

The problem here is that the report generation and PDF creation can take several minutes because of the volume of enterprise-wide data we need to process to create the report that can have 100 to 200 pages. The open/save dialog is currently appearing only after the whole thing (report generation and PDF creating) is over and I don't want my users to wait for minutes before they see the dialog. What I want to do is to force the open/save dialog upfront so that the user can choose one of the options and proceed with other things in the product while download is in progress.
I tried calling Response.Flush() after as follows before I call the actual report creation method, but that doesn't work. It would be awesome if someone can help me out.
Thanks
private void ExportReport(string strReportId, string strFormatId)
{
Response.Clear();
Response.ClearContent();
Response.BufferOutput = true;
Response.Buffer = true;
int iReportId = Convert.ToInt32(strReportId);
Report selReport = m_RFManager.GetReport(iReportId);
if (selReport == null)
{
Response.End();
}

// Let's start with letting the client(browser) know that we are in the
// process of a file download. This is needed because the report
// generation can take a while and we don't want the user to
// wait for the file download dialog.
string strFileExtension = m_RFManager.GetExportFormatFileExtension(strFormatId);
Response.ContentType = "application/x-download";
Response.AppendHeader("Content-Disposition", "attachment;
Title: Excellent   
Name: Sadat Akbar
Date: 4/20/2005 4:07:33 PM
Comment:
It is really a simple but extremly helpfull article for every one keep writting like this way by using simple examples.
Title: how can download pdf file   
Name: gautam bharti
Date: 4/15/2005 5:08:05 PM
Comment:
sir
pl send me code how can i download pdf file in asp.net
gautam.bharti@gmail.com
gautam.bharti@rediffmail.com
Title: Blank browser displayed after clicking save   
Name: amy
Date: 4/15/2005 8:29:21 AM
Comment:
\
Title: Misbeahvior   
Name: Petar
Date: 4/14/2005 4:24:44 AM
Comment:
am i the only one who experience strange misbehave with asp.net download via response object!?
when i use the code above my page from which the request has came FREEZE. I mean each postback to the server is the same request for download the file. Whatever i click on the page it starts downloading the file again. Has anyone experienced it!?? please mail me at: pip010@mail.bg
Title: File DownLoad   
Name: Anthoniz Raemsh
Date: 3/29/2005 6:52:43 AM
Comment:
This article is very useful for me but I want to find out if we can take this a step further. What I
mean by this is, can we find out if the user clicked "Open" or "Save" or "Cancel" buttons on the fi
le download dialog? Is there a handle that I returned with the what the user clicked. I'm more inter
ested to know if the user clicked cancel button. I need to do specific action if the user clicks can
cel button or the save button. Please help me. Thanks a ton. If you know the answer (or any ideas) p
lease email me at ramesha@hexaware.com. Thanks. Ramaa
Title: please help me   
Name: Hardik
Date: 3/12/2005 6:43:27 AM
Comment:
Hi,
I have seen this article it is really very nice. But i want that when i click on a particular button a report is generated in excel format automatically taking data from ms access and it just prompts me to save it. I dont want to display the report. So is it possible through ASP if yes then please describe me how can it be.
My mail id is hardik_bhatt@indiatimes.com..
plz reply back me as soon as possible..
its urgent.......

regards,
hardik
Title: download code   
Name: sirisha
Date: 3/4/2005 5:17:15 AM
Comment:
can you give the code for asp
Title: Download OK! But Open FAILS.....   
Name: Joe
Date: 1/17/2005 4:28:20 PM
Comment:
Hi
Selecting "download" on Document Download Dialog Box runs OK.
But selecting "open" (after saving to temp folder) fails
on IE 6. No Problem on Mozilla.
Any suggestions???
Title: Download Problem (Cont...)   
Name: Vikas Patwal
Date: 1/6/2005 4:22:34 AM
Comment:
I am trying to download the music file...
here is rest of the code:

ElseIf Trim(UCase(strFileExtname)) = UCase("avi") Then
Response.ContentType = "video/x-msvideo"
ElseIf Trim(UCase(strFileExtname)) = UCase("movie") Then
Response.ContentType = "video/x-sgi-movie"
Else
Response.ContentType = "application/octet-stream"
End If
End If
End If
Response.AddHeader("Content-Disposition", "attachment; filename=""" & StrFileName & """")
'Response.AppendHeader("Content-Disposition", "attachment; filename=""" & StrFileName & """")
Response.Flush()
Response.WriteFile(pStrFile)
Response.ClearHeaders()
Title: Downloding Problem   
Name: Vikas Patwal
Date: 1/6/2005 4:20:42 AM
Comment:
Hi,

By using almost same code around 80% time I am able to download the and sometimes I am getting problem.

Problem is that I am not getting the full download.

It shows download complete but downloads only some bytes and sometimes 0 bytes. Can anybody give me the solution for this. My code is as follows:

strFileExt = Split(StrFileName, ".")
If UBound(strFileExt) > 0 Then
strFileExtname = strFileExt(UBound(strFileExt))
If Trim(UCase(strFileExtname)) = UCase("au") Or Trim(UCase(strFileExtname)) = UCase("snd") Then
Response.ContentType = "audio/basic"
ElseIf Trim(UCase(strFileExtname)) = UCase("mid") Or Trim(UCase(strFileExtname)) = UCase("midi") Then
Response.ContentType = "audio/midi"
ElseIf Trim(UCase(strFileExtname)) = UCase("mpga") Or Trim(UCase(strFileExtname)) = UCase("mp2") Or Trim(UCase(strFileExtname)) = UCase("mp3") Then
Response.ContentType = "audio/mpeg"
ElseIf Trim(UCase(strFileExtname)) = UCase("aif") Or Trim(UCase(strFileExtname)) = UCase("aiff") Or Trim(UCase(strFileExtname)) = UCase("aifc") Then
Response.ContentType = "audio/x-aiff"
ElseIf Trim(UCase(strFileExtname)) = UCase("ram") Or Trim(UCase(strFileExtname)) = UCase("rm") Then
Response.ContentType = "audio/x-pn-realaudio"
ElseIf Trim(UCase(strFileExtname)) = UCase("rpm") Then
Response.ContentType = "audio/x-pn-realaudio-plugin"
ElseIf Trim(UCase(strFileExtname)) = UCase("ra") Then
Response.ContentType = "audio/x-realaudio"
ElseIf Trim(UCase(strFileExtname)) = UCase("wav") Then
Response.ContentType = "audio/x-wav"
ElseIf Trim(UCase(strFileExtname)) = UCase("mpeg") Or Trim(UCase(strFileExtname)) = UCase("mpg") Or Trim(UCase(strFileExtname)) = UCase("mpe") Then
Response.ContentType = "video/mpeg"
ElseIf Trim(UCase(strFileExtname)) = UCase("qt") Or Trim(UCase(strFileExtname)) = UCase("mov") Then
Response.ContentType = "video/quicktime"
ElseIf Trim(UCase(strFi
Title: u the man   
Name: ste
Date: 12/20/2004 10:50:15 PM
Comment:
u the man
Title: Great Article   
Name: David Ray
Date: 12/15/2004 11:30:13 AM
Comment:
Would love to know if there's a way to achieve the same effect via client-side scripting. Often, I won't have access to the server, but would love to embed this on a per page basis. Any ideas?

Thanks,
DR ;-}
Title: Downloading without Dialog   
Name: Glenn Rosenthal
Date: 11/23/2004 4:56:15 PM
Comment:
This article looks great. However, I want to be able to download files from the server to a specific local path and name, without prompting the user. Is this possible?
Title: Downloading Files from a Popup window is closing itself   
Name: Gina
Date: 11/8/2004 5:14:06 PM
Comment:
Thanks for this!

It works great except for when I want to use it from within a popup. If I use the above code from within a popup, the file Dialog box is displayed properly, but when I click save, it closes the Popup window that called it. Any idea how to stop that?! I'm pulling my hair out!
Title: very good article   
Name: veera reddy
Date: 11/4/2004 1:10:10 AM
Comment:
this is really a fantastic article. it gives nitty-gritty details about file downloading in asp.net i would like to say thanks to steve sharrock and mike .
Title: Thanks!! This was very helpful!!   
Name: Hemanshu Shah
Date: 11/1/2004 6:42:06 AM
Comment:
I wanted this solution from very very long time. Thanks for posting this article.

Just this much code works great,

Response.ContentType = "application/x-msdownload";
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.WriteFile(strLocalFile);

Content Type and the Content Disposition does the great magic for which i could not find any documentation earlier.

Regards,
Hemanshu
Title: How to display Chinese in the File Download (save) dialog?   
Name: minsun_y
Date: 8/5/2004 9:09:15 AM
Comment:
I want a method that how to display the filename in Chinese in the File Download (save) dialog?Because on my test,the filename can't corrected display.And,Can I find out if the user clicked "Open" or "Save" or "Cancel" buttons on the fi
le download dialog?
Title: Downloading Files - Forcing the File Download Dialog - taking this a step further.   
Name: Ramaa
Date: 7/8/2004 9:45:13 AM
Comment:
This article is very useful for me but I want to find out if we can take this a step further. What I mean by this is, can we find out if the user clicked "Open" or "Save" or "Cancel" buttons on the file download dialog? Is there a handle that I returned with the what the user clicked. I'm more interested to know if the user clicked cancel button. I need to do specific action if the user clicks cancel button or the save button. Please help me. Thanks a ton. If you know the answer (or any ideas) please email me at rum23@hotmail.com. Thanks. Ramaa
Title: Downloading Files -- Forcing the Download Page   
Name: 'lil Mikey from Andomeda Tennessee
Date: 7/7/2004 11:43:23 AM
Comment:
Mike Harber's code snippet was the first really complete example out of thousands. His thoroughness ended a long arduous quest. Pour me a tall one general, I'm a comin' home.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 10/20/2014 8:32:46 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search