Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:50:12+00:00 2026-06-02T16:50:12+00:00

I have some files in a folder on the harddrive, like C:\ExtraContent\ that has

  • 0

I have some files in a folder on the harddrive, like C:\ExtraContent\ that has some PDF files. This folder is not part of the website. I was able to successfully upload a PDF to this folder using the default ASP.NET FileUploader, no problem.

What I would like to do is, create a hyperlink that links to a PDF in that folder C:\ExtraContent\somePDF.pdf

I am able to get close using a Button with the following code:

protected void Button1_Click(object sender, EventArgs e)
{
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData("C:\ExtraContent\somePDF.pdf");
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}

The above works in terms of opening the file. But I can’t get this to work with an ASP.NET HyperLink.

The reason I want to use a HyperLink is so that the user can choose to right-click and Save As, to download a copy. If HyperLink controls can only link to relative paths, what can I do to get my desired result?

Note: making the files I’m trying to access part of the site is not practical for us.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:50:15+00:00Added an answer on June 2, 2026 at 4:50 pm

    Basically allowing access to the folder the way you describe is a real security risk (because it requires hacking at the permissions), isn’t trivial and in general should be avoided. The way that you achieve your desired behaviour is something along these lines.

    Firstly create a blank aspx or ashx page.

    Secondly, either in the Page_Load or ProcessRequest you want to use code along the following lines

    string filePath = "c:\\Documents\\Stuff\\";
    string fileName = "myPath.pdf";
    byte[] bytes = System.IO.File.ReadAllBytes(filePath + fileName);
    context.Response.Clear();
    context.Response.ContentType = "application/pdf";
    context.Response.Cache.SetCacheability(HttpCacheability.Private);
    context.Response.Expires = -1;
    context.Response.Buffer = true;
    context.Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"", "attachment", fileName));
    context.Response.BinaryWrite(bytes);
    context.Response.End(); 
    

    I haven’t tested this and taken it from my head so it might need some tweeks but the above code should get you on the right track to cause the persons browser to begin downloading the file you provide.

    EDIT: I just realized (after rereading your question) your problem was slightly different to what I thought, to get your issue resolved simply make the hyperlink button you are using link to a page that can process the request as described above. IE: An ashx or aspx page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some folder with different files. I want to use something like this:
Like, we have folder /images/ , it has some files inside. And the script
I have some PDF files in a public rails folder. I want to set
We have some files on our website that users of our software can download.
I have some folders/files in several drive like C:\New Folder C:\a.txt D:\New Folder\New Folder
I have some files in my folder /home/sample/* * /*.pdf and *.doc and *
I have some files in SVN marked ! filename That I would just like
I have some binary files in Tomcat webapp folder, that I wish user to
I have a MVC3 application with some XML files on the App_Data folder. To
I have a folder full of files and I want to search some string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.