简体   繁体   中英

Allow user to directly download a file clicking on a link

In my server which I shared, to store some files and I can access it from the run command like this from my local PC:

\\\\myserver\\myfolder\\file.pdf (which is technically on C:\\myfolder\\file.pdf in the server itself)

I am trying to display a link on my ASP.net webpage, built using C#, so the user can click on it and download the file to their local PC. My partial code-behind is this:

string newFileServer = "//" + System.Environment.MachineName + @"/myfolder/file.pdf";
tc.Text = "A completed PDF for " + k + " was generated successfully and saved to <a href=" + newFileServer + ">" + newFileServer + "</a>";

When I hover over the link in my local PC, I see the following:

http://myserver/myfolder/file.pdf

When I click on it, I get a 404 File or directory not found error.

How do I resolve it?

Map the folder in IIS as a virtual directory and then set your path accordingly.

  1. Go to IIS manager
  2. Select the site you want to have the files be accessible in.
  3. Right click and select add virtual directory.
  4. Give the path an alias.
  5. Then set the physical path.
  6. On the page create a link from http:// [domain] / [virtual directory] / [File] or use the virtual path / [Virtual Directory] / [File]

****** EDIT *******

tc.Text = "A completed PDF for " + k + " was generated successfully and saved to <a href='/PDFGenerate/file.pdf'>file.pdf</a> ";

您是否尝试过server.MapPath(“文件路径”)

your link is wrong patch, http or (localhost)?

you have not permission to access to out of server patch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM