Results 1 to 3 of 3

Thread: Why CSV file rename to XLS file when Downloading

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    Question 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.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    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:
    1. Private Sub setPDFToBrowserWindow(ByRef strPDFFileToView As String, ByRef strFileNameToShow as string)
    2.     ' **** Takes a given PDF File & outputs it to the users browser window. ****
    3.  
    4.         Dim fsCurPDFFileStream As System.IO.FileStream
    5.         Dim intPDFFileSize As Integer
    6.         Dim bytaryFileBBuffer() As Byte
    7.  
    8.         ' Open a new stream to the file.
    9.         fsCurPDFFileStream = New System.IO.FileStream(strPDFFileToView, System.IO.FileMode.Open)
    10.  
    11.         ' Retreive the amount of bytes in the file.
    12.         intPDFFileSize = Convert.ToInt32(fsCurPDFFileStream.Length)
    13.  
    14.         ' Read the byte stream into the byte array, then clost the stream.
    15.         ReDim bytaryFileBBuffer(intPDFFileSize)
    16.         fsCurPDFFileStream.Read(bytaryFileBBuffer, 0, intPDFFileSize)
    17.         fsCurPDFFileStream.Close()
    18.         fsCurPDFFileStream = Nothing
    19.  
    20.         ' Output the byte array from/to this webpage.
    21.         Response.ContentType = "application/pdf"
    22.         Response.OutputStream.Write(bytaryFileBBuffer, 0, intPDFFileSize)
    23.         Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileNameToShow
    24.         Response.Flush()
    25.         Response.Close()
    26.     End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width