Link to home
Start Free TrialLog in
Avatar of Webboy2008
Webboy2008

asked on

asp.net / upload

I have aspx webpage to allow user upload document. and that is working fine.
once the document is uploaded and saved into like C:\\Tmp\\doc.pdf

How can I open it on the web.
Avatar of volking
volking

You'll simply use something like Response.Redirect("C:\\Tmp\\doc.pdf",true)

Only you'll encounter a problem. Because, for the file to be accessible from your website, it must FIRST exist on a directory which the website has access to. I doubt your website has access to "C:/" ... right?

So,
(A) define a subdirectory under your website directory structure
(B) copy the file from "C:\\Tmp\\" to your new subdirectory
(C) use Response.Redirect(newdirectory + "\\doc.pdf",true)

To copy the file you'll need the physical path FROM and TO

You already know FROM - "C:\\Tmp\\doc.pdf"
The TO will be a function of HttpContext.Current.Server.MapPath
MapPath will help you get the PHYSICAL directory path to your website.

Let's say you make a subdirectory under your website named "MyTmpHoldingArea"

The copy-TO destination is
   Dim CopyToDPFE As String = HttpContext.Current.Server.MapPath("~/MyTmpHoldingArea/doc.pdf")

File.Copy(FROM, CopyToDPFE )

You may also need Path.Combine() if you're unsure of how to assemble the paths and file names properly.






Dim DPFE As String = HttpContext.Current.Server.MapPath("~/UserAccessWithdrawTemplate.htm")
Opps ... last line in last post was accidentally copied too!
Please ignore.
Avatar of Webboy2008

ASKER

I have c# in asp.net and I don't really understand what you are trying  to tell me.
The directory (c:\\tmp\document.pdf) already in one of the database table.

I will be able to get string like "c:\\tmp\\document.pdf.

Can you try to show me the working codes?  Thanks
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial