We help IT Professionals succeed at work.

asp.net / upload

Webboy2008
Webboy2008 asked
on
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.
Comment
Watch Question

Commented:
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)

Commented:
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")

Commented:
Opps ... last line in last post was accidentally copied too!
Please ignore.

Author

Commented:
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
Senior Software Engineer
Top Expert 2009
Commented:
Check:
http://stackoverflow.com/questions/4897197/open-external-pdf-file-in-asp-net-mvc-2

The simple solution is to add a link like:
<a href="ValidWebsiteFolder/mypdffile.pdf">Open mypdffile.pdf</a>

Notice that  you need a valid Website Folder location. (Tmp may not be accessible from your virtual directory)