Click here to Skip to main content
11,485,965 members (78,916 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
how to download in asp.net C# website? please type with code and namespace.
Posted 27-Dec-12 18:00pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This question makes no sense. You don't need code to offer a download from a website, you just need a link to the file. You can write code that writes a file to the Response object, that code is easy to find in your books or online if you need it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

 

 public static string ServerMapPath(string path)
    {
        return HttpContext.Current.Server.MapPath(path);
    }
    public static HttpResponse GetHttpResponse()
    {
        return HttpContext.Current.Response;
    }
    public static void DownLoadFileFromServer(string fileName)
    {
        //This is used to get Project Location.
        try
        {
            string filePath = ServerMapPath(fileName);
            //This is used to get the current response.
            HttpResponse res = GetHttpResponse();
            res.Clear();
            res.AppendHeader("content-disposition", "attachment; filename=" + filePath);
            res.ContentType = "application/octet-stream";
            res.WriteFile(filePath);
            res.Flush();
            res.End();
        }
        catch (Exception ex)
        {
           
        }
    }
 
 protected void Button2_Click(object sender, EventArgs e)
    {
DownLoadFileFromServer("~/Storage/" + txtname.Text);
}
 




file need to be in same directory of website in some folder int this case folder name is Storage
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 375
1 Maciej Los 365
2 C#developer.asp 204
3 Mehdi Gholam 190
4 OriginalGriff 149
0 Sergey Alexandrovich Kryukov 8,819
1 OriginalGriff 7,982
2 Sascha Lefèvre 3,199
3 Maciej Los 2,841
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2015
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