Click here to Skip to main content
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 Sergey Alexandrovich Kryukov 379
1 Nirav Prabtani 266
2 Abhinav S 210
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,545
1 Sergey Alexandrovich Kryukov 6,757
2 Maciej Los 3,909
3 Peter Leow 3,693
4 CHill60 2,712


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