473,378 Members | 1,397 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,378 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 1971
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.