Download Aspx File From Website

  1. How To Download Files From Website
  2. Download Files From Website Directory
  3. Download Aspx File From Website To Pdf

What is the best way to implement, from a web page a download action using asp.net 2.0?

The file download box appears with the name of the webpage and its extension (pagename.aspx). After download, if you rename it back to the actual name; file opens successfully. After download, if you rename it back to the actual name; file opens successfully.

Log files for a action are created in a directory called [Application Root]/Logs. I have the full path and want to provide a button, that when clicked will download the log file from the IIS server to the users local pc.

Community
HadleyHopeHadleyHope
9881 gold badge8 silver badges19 bronze badges

2 Answers

Does this help:

Response.TransmitFile is the accepted way of sending large files, instead of Response.WriteFile.

MartinMartin
28.6k17 gold badges86 silver badges125 bronze badges


Update:

The initial code

has 'inline;attachment' i.e. two values for Content Disposition.

Don't know when exactly it started, but in Firefox only the proper file name was not appearing. The file download box appears with the name of the webpage and its extension (pagename.aspx). After download, if you rename it back to the actual name; file opens successfully.

As per this page, it operates on First Come First Served basis. Changing the value to attachment only solved the issue.

PS: I am not sure if this is the best practice but the issue is resolved.

BiLaLBiLaL

Not the answer you're looking for? Browse other questions tagged asp.netfiledownload or ask your own question.

In my web app, I have an aspx page which contains an html table and several lines of text. I need users to be able to download this whole page as a separate file.

How to open aspx file

In the past I have used the a webclient to do this:

but it appears this is only able to download html pages.

Can this be done?

UrbycozUrbycoz
2,63318 gold badges52 silver badges95 bronze badges

2 Answers

The reason you can only download HTML is because .aspx is not served over the internet (only the resulting HTML is).

When you are doing the myWebClient.DownloadFile() the application is simply making a GET request to the URI and saving the resulting HTML. The .aspx never leaves the server - rather it is processed server side resulting in the HTML you are ending up with.

m.edmondsonm.edmondson
20.7k23 gold badges101 silver badges177 bronze badges

How To Download Files From Website

.ASPX is a scripted page, so you can't actually download the original ASPX. The IIS server on the other end has a handler for .aspx resulting in .NET Processing it. Generally, you don't want a server returning raw ASPX source.

Download aspx file from website download

It would require special handling on the server side to be able to get a raw ASPX page. For instance, you could create an ASHX script handler that does it for you, you'd request something like getfile.ashx?filename=myfile.aspx and the getfile.ashx handler would read the ASPX page off the disk and write that as the response. (Security note: If this is the route you choose, make sure to sanitize the page that is specified so they don't do something silly like getfile.ashx?filename=C:mysecretfile.txt) It would be even better to set the trust level of that handler to medium or lower.

But that all requires serverside development. From the client side, there isn't anything you can do until the server wants to play along.

Here is an example of a file handler:

From

You can setup the handler either inside of an ASHX or through the httpHandlers section in the web.config.

Or if you are using MVC2+, you don't need an HTTP Handler as you can just use an action to achieve the same thing:

vcsjonesvcsjones

Download Files From Website Directory

108k23 gold badges252 silver badges258 bronze badges

Download Aspx File From Website To Pdf

Not the answer you're looking for? Browse other questions tagged asp.netvb.netdownload or ask your own question.