Print Page | Close Window

Save csv file type as txt

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6208
Printed Date: 31 March 2026 at 1:17pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Save csv file type as txt
Posted By: itindy
Subject: Save csv file type as txt
Date Posted: 06 October 2003 at 11:40am
I am trying to save a csv file as either a csv or txt on the user's computer.  When I click to save the file, then select the drop box to save as a text file, there is no option.  I can save as a csv file or I can select "All Files" and add .txt to the file name.  Since most users will not know to select "All Files" and add the txt extension, I need a way to add the text file option to the drop box.  Is there an easy way to do this in ASP or any other method?



Replies:
Posted By: MorningZ
Date Posted: 06 October 2003 at 12:56pm
you could use the FileSystemObject to "rename" (technically there is no rename method, but you could use the "move" method to accomplish the same) the file to the .txt extension

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: fernan82
Date Posted: 06 October 2003 at 7:09pm

You can also use the Stream Object to make the user download the file with a different name..... here's a sample function that will download a file called File.csv located on D:\ on your server as File.txt. You can even change the whole name:

Response.Buffer = True
Response.Clear

Call ForceDownload("D:\File.csv", "File.txt")

Function ForceDownload(strPath, strfilespec)      

         Dim oStream

         Set oStream = server.createobject("ADODB.Stream")

         oStream.Open
         oStream.Type = 1 ' Binary 
         oStream.LoadFromFile strPath        
          
         Respon se.ContentType="application/unknown"
         Respon se.AddHeader "Content-Disposition","attachment; filename=" & chr(34) & strfilespec & chr(34) 
         Respon se.BinaryWrite oStream.Read

         Response.Flush
         oStream.Close
         Set oStream = Nothing 
End Function

 



-------------
FeRnAN
http://www.danasoft.com/">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net