|
-
Jun 18th, 2006, 09:10 PM
#1
Thread Starter
Addicted Member
Why CSV file rename to XLS file when Downloading
I have create a CSV file in comma-delimited format(Report.csv). When I use asp(Response.Redirect("Report.csv")) . Then it prompt user to save as .xls file. Excel does not display properly with this .xls file that renamed from .csv file. I want user to save as .csv file. How can i do? Thanks.
-
Jun 19th, 2006, 02:57 AM
#2
Re: Why CSV file rename to XLS file when Downloading
You can use a stream object to do this. This streams the file out to the user's browser (which is more secure way of showing a user a file from your server too), and this way allows you to specify:
- An application which this file should open with
- The filename and extension the user will see in the "do you want to open or save this file" box
You should be able to modify the below to specify notepad and a filename with a *.csv file extension...
VB Code:
Private Sub setPDFToBrowserWindow(ByRef strPDFFileToView As String, ByRef strFileNameToShow as string)
' **** Takes a given PDF File & outputs it to the users browser window. ****
Dim fsCurPDFFileStream As System.IO.FileStream
Dim intPDFFileSize As Integer
Dim bytaryFileBBuffer() As Byte
' Open a new stream to the file.
fsCurPDFFileStream = New System.IO.FileStream(strPDFFileToView, System.IO.FileMode.Open)
' Retreive the amount of bytes in the file.
intPDFFileSize = Convert.ToInt32(fsCurPDFFileStream.Length)
' Read the byte stream into the byte array, then clost the stream.
ReDim bytaryFileBBuffer(intPDFFileSize)
fsCurPDFFileStream.Read(bytaryFileBBuffer, 0, intPDFFileSize)
fsCurPDFFileStream.Close()
fsCurPDFFileStream = Nothing
' Output the byte array from/to this webpage.
Response.ContentType = "application/pdf"
Response.OutputStream.Write(bytaryFileBBuffer, 0, intPDFFileSize)
Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileNameToShow
Response.Flush()
Response.Close()
End Sub
-
Jun 19th, 2006, 03:04 PM
#3
Re: Why CSV file rename to XLS file when Downloading
Are you sure it's being saved as XLS, or are you just getting the XLS icon? Because Excel takes over as the default CSV reader.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|