PDA

View Full Version : File Upload and Display


aspq
05-08-2004, 12:45 PM
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

bruce
05-09-2004, 01:26 AM
I don't think you can do that.

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

[b]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">

JmH
05-19-2004, 05:47 AM
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