Click here to Skip to main content
12,698,048 members (23,254 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET
what do i do to allow a client to download a file from my website?
Posted 12-Nov-12 15:23pm
Sergey Alexandrovich Kryukov 12-Nov-12 23:31pm
All resources you put in your site are downloadable. You don't need to do anything to allow that, unless you need some extra functionality.

If you are talking about ASP.NET, tag it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Once you provide a link to your file in the web page, the client browser will take care of the download.
Try File Download in ASP.NET and Tracking the Status of Success/Failure of Download[^].
Sergey Alexandrovich Kryukov 12-Nov-12 23:33pm
That is useful link, my 5, but I think main answer to the question is in my comment to the question, please see. I looks like OP does not clearly understand how Web works, even at the level of the Web browser user...
Member 9445358 12-Nov-12 23:47pm
who is OP?
Sorry... it means the author of the Original Post -- you, in this case...
Member 9445358 12-Nov-12 23:46pm
When i try to link to file i get a 403 error(not allowed)
Not clear what did you do, exactly.
Member 9445358 13-Nov-12 0:24am
i set Hyperlink's NavigateUrl equal to filepath/filename. When click on link,get 403 error
Can you be as specific as it is required to get help?! Exact lines of code, please. And also show how it looks on client side (Browser's View / Page Source). Chances are, this is just not a valid path.
Member 9445358 13-Nov-12 23:15pm
I thought maybe i had to deal with filestream, but you seem to be saying I don't need to do that if i don't want to download in chunks?
Here is what i did in code:
<asp:HyperLink ID="HyperLink1" NavigateUrl="/App_Data/filename.pdf" CssClass="hidden" runat="server">
<asp:Image ID="Image1" ImageUrl="/img/Adobe_PDF_Icon.svg.png"
Style="position: relative; float: right;" Width="64" Height="68" alt="Adobe
PDF Icon.svg" runat="server" />

Sergey Alexandrovich Kryukov 13-Nov-12 23:24pm
Did you mean "./img" and "./App_Data" directories? What is currently written look like absolute paths, relative to the volume root, which are most likely not accessible to your site. Only the directories under the root directory of your site are accessible...
Sergey Alexandrovich Kryukov 13-Nov-12 23:38pm
OK, it's getting too far... May be you need to resort it to a different thing -- to keep it simple. I decided to add my own answer -- please see.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

With some file types, the web server (IIS) does not know what to do or blocks their download for security reasons (.mdb). The easiest solution is to zip the files which are to be downloaded - the extension .zip is normally registered. Otherwise you may need to register a new file type with IIS.
A good advice, by the way. My 5. But if you look at comments to Solution 1, you will probably see that OP is not yet there -- it's still about understanding how Web works... :-)
Bernhard Hiller 14-Nov-12 2:46am
Many people do not give enough information to distinguish between a general failure (cannot download any file) and a specific failure (cannot download a specific file/file type). And when it comes to some distribution between server and client (Web, RDP, Citrix,...), even many experienced people fail to see on which side the problem originates.
Sergey Alexandrovich Kryukov 14-Nov-12 11:34am
Agree; only your word "experienced" in this context looks questionable. If by "experienced" you mean "having long-time experience", then yes -- some people fail to understand what they do during lifetime of experience; I met an old person with most amazing lack if understanding and inability to make things work properly in 2008, will never forget the frustration. I just don't call such people "experienced".
Member 9445358 19-Nov-12 20:44pm
It turns out there are special restrictions on the App_Data folder, and that is why it wouldn't download!
Sergey Alexandrovich Kryukov 19-Nov-12 21:22pm
Makes no sense, really. If a user see the anchor, its different resource, it can be downloaded.

And please, don't put your comments as "solutions". "Add your solution here" is reserved only for the cases when you provide some help in response to some question. If it is not, it will be removed, but, worse for you, many members would down-vote it and even report you for abuse, which you don't want, so I removed that post.

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I don't understand your concern, but most likely you just don't understand some very basic things. If you want the user to download some file, you can simply write:

<a href="somefile.pdf'>Some PDF document</a>

On anchor click, if the client has PDF support embedded in browser or available as plug-in, it will be loaded in the page, otherwise the user will get a choice do download it or open with some viewer, default or by the user's choice; in all cases, the user can simply download the file, as always with the anchor. With other file types (very typically, *.zip), the only option will be downloading. This code assumes that you place the file in the same directory as the present page, but it can be any directory relative to this page. Avoid using absolute paths, or use just the full URL, starting with the scheme.

Sorry if this is too trivial and you already know all that, but it actually answers your question. If you need some extra downloading features, ask about them specifically. But better start from here and hopefully you will be able to learn advanced things later.

As to your question on your error 403, please see the answer in my comment, in the discussions of the Solution 1.

On this problem, see also:[^],[^].

Are you getting the idea? Normally, the applications are executed under HTTP server in a sandboxed environment which exclude the access to any directories outside the root directory mapped to the site.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100