Solved

Text files opening up as html instead of Notepad/Wordpad in IE

Posted on 2004-10-22
328 Views
Last Modified: 2008-01-16
I have a web application that allows a user to download a etxt file within their browser. Several end users have reported that after applying XP SP2 the files open up in IE as html. Is there a way to change this so that the IE uses Notepad/Wordpad to open the files?

Thanx
0
Question by:factsmgt
    5 Comments
     
    LVL 4

    Expert Comment

    by:lepiaf
    Are text files associated to IExplorer?

    You can view that in the files properties, in the 1st tab under opens with APP_NAME -> hit the change button, in case it is associated to IExplorer.

    is that the issue?

    cheers,
    LePiaf
    0
     

    Author Comment

    by:factsmgt
    text files are associated with Notepad. If I open the file through Windows explorer the file will open in Notepad.
    0
     
    LVL 4

    Expert Comment

    by:Danielcmorris
    Here ya go:

    <%
    Response.Buffer = True

    strFileName=request("strFileName")        ' Set file name
    strFilePath=server.mappath(strFilename) ' Set path of file
    set fso=createobject("scripting.filesystemobject")
    set f=fso.getfile(strfilepath)
    strFileSize = f.size
    set f=nothing: set fso=nothing
    Const adTypeBinary = 1
    Response.Clear
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath
    strFileType = "application/text" ' change to the correct content type for your file
    Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
    Response.AddHeader "Content-Length", strFileSize
    Response.Charset = "UTF-8"
    'Response.ContentType = strFileType
    Response.BinaryWrite objStream.Read
    Response.Flush
    objStream.Close
    Set objStream = Nothing
    %>

    make a new page.  paste this script into it.  call it "forcedownload.asp".  make the link on your file something like:

    <a href="forcedownload.asp?strFileName=my_text_file.txt">my text file</a>

    It will force the user to download the file rather than opening it up in the browser.  Very nice.  I got it from some site a long time ago.  (maybe even this one)  It has saved me a huge amount of trouble.  Especially because you can set the file path to someplace other than your website.  Places where you don't want people to be able to browse to.  

    Good luck,

    -Dan
     
    0
     

    Author Comment

    by:factsmgt
    Does anyone have any insight on how to correct this on the client side?
    0
     
    LVL 4

    Accepted Solution

    by:
    It would be an incredible pain in the butt.  You may be able to set your user's computers to disassociate IE with txt files, but I couldn't tell you how to do it.  

    If you REALLY wanted to fix it so your XP users would get notepad, you can create a little activex object that would pull the document off your site, save it to a temp file, then open that file with notepad.

    Then again, you'd have to screen the users so only Windows users would get the ActiveX.  For linux and mac, well.... a Java app.  All around Yuck.

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now