troubleshooting Question

Download function open the word document as webpage in microsoft word. But When directly open from the folder it opens correctly. How to solve this problem?

Avatar of casstd
casstd asked on
ASP
29 Comments1 Solution468 ViewsLast Modified:
Hi,

       I have the following code to download file from the website (pdf, word etc.,).
I have problem when open the document file. It does not open properly in microsoft word. i.e it shows the symbol webpage in the word. Hope it opens as webpage not document in Microsoft word. I found this when i directly open the doucment there is no webpage symbol appears in the word and the document open properly but when i click the download button it opens as webpage in word. How to solve this problem?

Thank you.

set fs=server.CreateObject("scripting.filesystemobject")
  if fs.FileExists(server.MapPath(snfile))=true then
    set objfile=fs.GetFile(server.MapPath(snfile))
    size=objfile.size
    fname=objfile.name
    mime_type="application/save-as"
    Response.AddHeader "Expires:",0
    Response.ContentType=mime_type
    Response.AddHeader "Content-Disposition","attachment; filename="&fname
    set objStream =server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type=1
    objStream.LoadFromFile server.MapPath(snfile)
    Response.BinaryWrite objStream.Read
  else
    Response.Write "File not found!"
    Response.End
  end if
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 29 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 29 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros