SearchForKnowledge
SearchForKnowledge

Reputation: 3751

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?

Upvotes: 1

Views: 1791

Answers (3)

CBRRacer
CBRRacer

Reputation: 4659

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>";

Upvotes: 1

mohsen solhnia
mohsen solhnia

Reputation: 376

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

you have not permission to access to out of server patch

Upvotes: 1

Chris Bahr
Chris Bahr

Reputation: 90

Have you tried server.MapPath("path to file")

Upvotes: 1

Related Questions