473,231 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Text file download from website

I am trying to download a text file that my .NET page has just created based
on entered parameters on the web page. Everything seems to work and the file
is created. I am using the following code to start the download process:

Response.Clear()
Response.ContentType = "text/plain"
Response.AppendHeader("Content-Disposition", "attachment; filename="
& fileName)
Response.AppendHeader("Content-Description", "This is your Cost
Journal import file.")
Response.Flush()
Response.WriteFile(fileName)
Response.End()

The download does start. However, the "FileName" suggested in the dialoge
to the user is the .NET webpage name without an extention, there is no
default file type, and the description does not display. If a file name is
entered by the user in the "save" the proper information is downloaded. Can
anyone suggest one of two things:
1. What might I be doing incorrectly?
2. Is there a better/simpler way to download a file which has just been
created?
Thank you for your help in advance.
Tom Youngquist
To***@ix.netcom.com
Jul 21 '05 #1
2 1962
why not just use:
response.redirect("myfile.txt")

I'm missing something, I'm sure.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Tom Youngquist" <To***********@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code to start the download process:

Response.Clear()
Response.ContentType = "text/plain"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName)
Response.AppendHeader("Content-Description", "This is your Cost
Journal import file.")
Response.Flush()
Response.WriteFile(fileName)
Response.End()

The download does start. However, the "FileName" suggested in the dialoge
to the user is the .NET webpage name without an extention, there is no
default file type, and the description does not display. If a file name is entered by the user in the "save" the proper information is downloaded. Can anyone suggest one of two things:
1. What might I be doing incorrectly?
2. Is there a better/simpler way to download a file which has just been
created?
Thank you for your help in advance.
Tom Youngquist
To***@ix.netcom.com

Jul 21 '05 #2
<%@ Page language="VB" Debug="true"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
If Not IsPostBack Then
Dim PathVirtual as string = Request.QueryString("Filename")
Dim strPhysicalPath As String
Dim objFileInfo As System.IO.FileInfo
Try
strPhysicalPath = Server.MapPath(PathVirtual)
'exit if file does not exist
If Not System.IO.File.Exists(strPhysicalPath) Then Exit Sub
objFileInfo = New System.IO.FileInfo(strPhysicalPath)
Response.Clear()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment;
filename=" & Request.QueryString("filename"))
'objFileInfo.Name)
Response.AddHeader("Content-Length",
objFileInfo.Length.ToString())

Response.ContentType = "application/octet-stream"
Response.WriteFile(objFileInfo.FullName)

Catch
'on exception take no action

Finally
'System.IO.File.delete(strPhysicalPath)
'Response.End()

End Try

End If
End Sub
sub funclose(obj as object, e as eventargs)
try
Dim PathVirtual as string = Request.QueryString("Filename")
Dim strPhysicalPath As String
strPhysicalPath = Server.MapPath(PathVirtual)
System.IO.File.delete(strPhysicalPath)
catch
End try
Response.Write("<script language=javascript>" & vbcrlf)
Response.write("self.close();" )
Response.Write("</" & "script>")
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<table width="100%" border="0"><tr><td align="center"
width="100%"><asp:button id="btnclose" OnClick="funclose" text="Close"
runat="server"/></td></tr></table>
</form>
</body>
</html>
Find Code

"Nick Malik [Microsoft]" wrote:
why not just use:
response.redirect("myfile.txt")

I'm missing something, I'm sure.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Tom Youngquist" <To***********@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
I am trying to download a text file that my .NET page has just created

based
on entered parameters on the web page. Everything seems to work and the

file
is created. I am using the following code to start the download process:

Response.Clear()
Response.ContentType = "text/plain"
Response.AppendHeader("Content-Disposition", "attachment;

filename="
& fileName)
Response.AppendHeader("Content-Description", "This is your Cost
Journal import file.")
Response.Flush()
Response.WriteFile(fileName)
Response.End()

The download does start. However, the "FileName" suggested in the dialoge
to the user is the .NET webpage name without an extention, there is no
default file type, and the description does not display. If a file name

is
entered by the user in the "save" the proper information is downloaded.

Can
anyone suggest one of two things:
1. What might I be doing incorrectly?
2. Is there a better/simpler way to download a file which has just been
created?
Thank you for your help in advance.
Tom Youngquist
To***@ix.netcom.com


Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
4
by: Gary | last post by:
Hello, I am using asp classical and connection to SQL 2000 on a Windows 2000 machine. I am using this code to generate a text file when the user clicks on the link. This is so the user can...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
3
by: Loane Sharp | last post by:
Hi there I'm new to VB.NET programming and really programming in general. I have a small binary file on my website that I want to download programmatically onto my local hard drive. I can...
2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
1
by: Prabhat | last post by:
Hello friends, I have one TEXT file that I use to log download information from website. The file will have unique Login ID for the downloads. When the user will come for next time for download...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
1
by: R.A.M. | last post by:
Hello, I am learning PHP5. I have little experience. I have created a website in which I want to put a link to download a text file. When I used simple <a href="Dir/File.txt">Download file</a> I...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.