File Upload and Display

Discussion in 'ASP.NET / ASP.NET Core' started by aspq, May 8, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi, I have uploaded files to a folder on my computer and everything works fine. when I try to display the content of the file, I use this code:

    Dim CNAME as String = Server.MapPath("..\uploaded_files\" & oComm.Parameters( "@c_randName" ).Value )
    Dim oStreamReader as StreamReader
    oStreamReader = File.OpenText(CNAME)
    Dim fileContent as String = oStreamReader.ReadToEnd()
    lblOutput.Text = fileContent
    oStreamReader.Close()

    this code only reads and display files with 'txt' extention, it doesn't disply 'doc' files. How can I change the code so that it can read and display .doc files correctly?
    Many thanks
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    I don't think you can do that.

    .doc document is in a special format and using steamreader probably won't work.

    quote:Originally posted by aspq

    Hi, I have uploaded files to a folder on my computer and everything works fine. when I try to display the content of the file, I use this code:

    Dim CNAME as String = Server.MapPath("..\uploaded_files\" & oComm.Parameters( "@c_randName" ).Value )
    Dim oStreamReader as StreamReader
    oStreamReader = File.OpenText(CNAME)
    Dim fileContent as String = oStreamReader.ReadToEnd()
    lblOutput.Text = fileContent
    oStreamReader.Close()

    this code only reads and display files with 'txt' extention, it doesn't disply 'doc' files. How can I change the code so that it can read and display .doc files correctly?
    Many thanks
    </blockquote id="quote"></font id="quote">
     
  3. JmH

    JmH

    Try this
    'Set the content type to the specific type that you are sending.
    Response.ContentType = "application/Word"

    Const adTypeBinary = 1
    Dim strFilePath

    strFilePath = "C:\folder\something.doc" 'This is the path to the file on disk.

    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath

    Response.BinaryWrite objStream.Read

    objStream.Close
    Set objStream = Nothing

    MCP, MCSD, MOUSE
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page