tags:

views:

177

answers:

2

I need to download an Access file(Inbox.mdb) file when clicked on asp.net button...?
How do i do this is C# / ASP.NET .
Any help would be appreciated.

A: 

If the file is just publically hosted on your server you don't nee to use any C#/ASP.NET functionality.

Just add a normal

<a href="~/Path/To/Inbox.mdb">Link</a>

If you have to use a server side button then

Response.Redirect("~/Path/To/Inbox.mdb");

will redirect to that file and cause the browser to download it.

If its stored elsewhere (i.e. not publically accessible) then you'll need to stream it from its location on the server. Have a look on google for examples of streaming files via the Response object.

Eoin Campbell
+1  A: 
<!-- in your aspx file -->
<asp:button id="btnDownload" runat="server" onclick="btnDownload_Click" text="Download Your MDB" />

// and then in your codebehind file
protected void btnDownload_Click(object sender, EventArgs e)
{
    string pathToYourMDB = @"c:\stuff\test.mdb";
    string downloadName = "YourData.mdb";

    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + downloadName+ "\"");
    Response.TransmitFile(pathToYourMDB);
    Response.End();
}
LukeH