PC Review


Reply
Thread Tools Rate Thread

downloading a file in ASP.NET app

 
 
AlexB
Guest
Posts: n/a
 
      1st Aug 2003
I'm trying to download a text file to an IE client using
the following code. The problem is that the saved file
also includes the html for the page.

Any ideas anyone?


Private Sub Button5_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button5.Click

Dim strFileToDownload$ = "C:\test.log"
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-
Disposition", "attachment; filename = " &
System.IO.Path.GetFileName(strFileToDownload))
Response.Flush()
Response.WriteFile(strFileToDownload)

End Sub
 
Reply With Quote
 
 
 
 
Billy Jacobs
Guest
Posts: n/a
 
      1st Aug 2003
You might try contenttype/text

Alternatively

You can try the following: The link can be placed into
a .aspx page as well. When the user clicks the link he/she
will be prompted to open or save the file.
<html>
<body>
<a href="download.txt">Download File</a>
</body>
</html>





>-----Original Message-----
>I'm trying to download a text file to an IE client using
>the following code. The problem is that the saved file
>also includes the html for the page.
>
>Any ideas anyone?
>
>
>Private Sub Button5_Click(ByVal sender As

System.Object,
>ByVal e As System.EventArgs) Handles Button5.Click
>
> Dim strFileToDownload$ = "C:\test.log"
> Response.ContentType = "application/octet-stream"
> Response.AddHeader("Content-
>Disposition", "attachment; filename = " &
>System.IO.Path.GetFileName(strFileToDownload))
> Response.Flush()
> Response.WriteFile(strFileToDownload)
>
>End Sub
>.
>

 
Reply With Quote
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      4th Aug 2003
Thanks Billy for suggestions.

Hi AlexB,

Here are 3 Members of Response:
Clear Clears all content output from the buffer stream.
Flush Sends all currently buffered output to the client.
End Sends all currently buffered output to the client, stops execution of
the page, and raises the Application_EndRequest event.

So, the code should be like this:
//Response.Flush();
Response.Clear ();
Response.WriteFile(strFileToDownload);
Response.End ();

Hope this helps.


Best Regards,
Lewis

Get Secure! - <www.microsoft.com/security>
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "AlexB" <(E-Mail Removed)>
| Sender: "AlexB" <(E-Mail Removed)>
| Subject: downloading a file in ASP.NET app
| Date: Fri, 1 Aug 2003 13:45:24 -0700
| Lines: 19
| Message-ID: <03d401c3586d$d52ecec0$(E-Mail Removed)>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcNYbdUuIaLhfqpbSbWrlNVaajyWHQ==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103166
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I'm trying to download a text file to an IE client using
| the following code. The problem is that the saved file
| also includes the html for the page.
|
| Any ideas anyone?
|
|
| Private Sub Button5_Click(ByVal sender As System.Object,
| ByVal e As System.EventArgs) Handles Button5.Click
|
| Dim strFileToDownload$ = "C:\test.log"
| Response.ContentType = "application/octet-stream"
| Response.AddHeader("Content-
| Disposition", "attachment; filename = " &
| System.IO.Path.GetFileName(strFileToDownload))
| Response.Flush()
| Response.WriteFile(strFileToDownload)
|
| End Sub
|

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
downloading excel file for open causes "file is locked for editing HigherImpact Microsoft Excel Programming 0 3rd Dec 2007 06:23 PM
File Downloading... =?Utf-8?B?Um9iS2lubmV5MQ==?= Microsoft C# .NET 5 8th Nov 2006 01:55 AM
File downloading problem on long file names prakash.kgm@gmail.com Windows XP Internet Explorer 4 14th Sep 2006 05:42 AM
Downloading File =?Utf-8?B?SmFuaQ==?= Microsoft Access VBA Modules 0 20th Oct 2004 02:33 PM
Downloading file from aspx page -- change file name? Brandon Potter Microsoft ASP .NET 2 12th Mar 2004 03:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 AM.