confusedMind
confusedMind

Reputation: 2653

Issue downloading excel file using anchor tag

I make HTML on runtime , and this is one of the lines:

<a target=\"_blank\" href=\""+filepath+"\">Download</a>

Where filepath is like F:\Website\Files\records.xlsx

The issue the the above opens a new tab with the file path in it but nothing happens the browser says the address was not understood. However when i click the address and press enter i see the download popup and can't seem to find out the issue.

Any suggestions?

Upvotes: 0

Views: 1599

Answers (1)

Christoph Fink
Christoph Fink

Reputation: 23103

Where filepath is like F:\Website\Files\records.xlsx

How should a "local path" work on a website (I assume you are not targeting an intranet, where F:\ is a shared drive for everyone. If so please update the question adding that info)?

You possible want something like:

string filepath = "records.xlsx";
string anchor = "<a target=\"_blank\" href=\"/Files/" + filepath + "\">Download</a>";

And under the URL /Files/.... you map a file handler which sends the file to the client. If you tell us what technology you are using (WebForms, MVC, ...) I can give you an example how to do this...

Upvotes: 1

Related Questions