Click here to Skip to main content
11,577,258 members (50,653 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 17: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 DamithSL 155
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 676
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web04 | 2.8.150603.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