0

How to get file from disk and write it to response?

We have some files on disk, and I want to allow logged users to download them.

I restricted access to them via direct link, so I just need how to get them from disk and give them to users via asp.net application.

Thanks

el ninho
  • 4,183
  • 15
  • 56
  • 77
  • Your question might get closed. The `ASP.NET` tag for your question makes it too vague. ASP.NET is a broad set of APIs. Are your talking about ASP.NET MVC, ASP.NET WebApi, ASP.NET Generic Web handler (ashx) or a classic ASP.NET page handler (aspx)? – Sylvain Dec 24 '13 at 19:20

1 Answers1

1

You can just use Response.TransmitFile method, like this:

protected void SomeButton_Click(object sender, EventArgs e)
{
    string fileName = @"D:\somepath\somefile.doc";

    Response.TransmitFile(fileName);
}

There is also another method Response.WriteFile. You can read difference between them here

Community
  • 1
  • 1
Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67