Hello All, We are going to start new batch from next week. message/call or mail us for more details.

File Download in Asp.Net with C#


Introduction

This code is provide a download functionality in Asp.Net with c#.. 

So to download any file in ASP.Net using C# import this namespace

Namespace
using System.Net;
Use the code
First we create source file using Button, TextBox and Label Control..
Enter path in Textbox
Example:-E-Book/HiFriends.doc
and download your file in your pc.
<body>
<
form id="form1" runat="server">
<
div>
<
table class="style1">
<
tr>
<
td style="text-align: right">Select Path :-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<
td><asp:TextBox ID="txtFileName" runat="server" Width="201px"></asp:TextBox></td>
</
tr>
<
tr>
<
td>&nbsp;</td>
<
td>&nbsp;</td>
</
tr>
<
tr>
<
td>&nbsp;</td>
<
td><asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Download" /></td>
</
tr>
</
table>
</
div>
</
form>
</
body>
This Code Write in your cs file 
protected void Download_Click(object sender, EventArgs e)
{

    try

    {
        string strURL = txtFileName.Text;
        WebClient req = 
new WebClient();
        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ClearContent();
        response.ClearHeaders();
        response.Buffer = 
true;
        response.AddHeader(
"Content-Disposition""attachment;filename=\"" + Server.MapPath(strURL) + "\"");
        byte[] data = req.DownloadData(Server.MapPath(strURL));
        response.BinaryWrite(data);
        response.End();
    }

    catch
 (Exception ex)
    {
    }
}

25 comments:



  1. This is the information that I was looking for.. Thanks for the efforts you put to gather such a nice content and posted here.
    http://www.iqonlinetraining.com/asp-dotnet-online-training/

    ReplyDelete
  2. Excellent information with unique content and it is very useful to know about the information based on blogs.
    Dot Net Online Training Hyderabad

    ReplyDelete
  3. I am glad to read this. Thank you for this beautiful content, Keep it up. Techavera is the best DTP training course in Noida. Visit us For Quality Learning.Thank you

    ReplyDelete
  4. Nice and good article. It will helpful for dotnet students and developers.Thanks for sharing this useful information. If you want to learn dotnet course in online, please visit below site.
    dotnet Online Training, dotnet course, dotnet online training in kurnool, dotnet online training in hyderabad, dotnet online training in bangalore, online courses, online learning, online education, trending courses, best career courses

    ReplyDelete

  5. Nice blog..! I really loved reading through this article. Thanks for sharing such
    a amazing post with us and keep blogging...

    asp dotnet training in hyderabad

    ReplyDelete

  6. hi your blog Article is very nice & thanks for sharing the information.

    dotnet online coaching in hyderabad

    ReplyDelete
  7. Nice blog..! I really loved reading through this article. Thanks for sharing such
    a amazing post with us and keep blogging...
    tableau online training hyderabad!
    tableau developer course!

    ReplyDelete
  8. If more people that write articles involved themselves with writing great content like you, more readers would be interested in their writings. I have learned too many things from your article.
    trending courses

    ReplyDelete
  9. Excellent information with unique content and it is very useful to know about the information based on blogs.
    Dot Net Online Training
    Visit us: Dot Net Online Training

    ReplyDelete
  10. Thank you for sharing valuable information.
    Visit us: Java Online Course
    Visit us: Learn Java Online

    ReplyDelete
  11. Hi, I read your whole blog. This is very nice. Good to know about the .net and is very demanding in future. We are also providing various Microsoft .Net Training & Certification Courses, anyone interested can .net certification for making their career in this field.

    ReplyDelete
  12. Jó honlap : Zonahobisaya
    Jó honlap : Biografi
    Jó honlap : Tersempit
    Jó honlap : Zonahobisaya
    Jó honlap : Sinopsis Film Terbaru
    Jó honlap : Zonahobisaya
    Jó honlap : Zonahobisaya
    Jó honlap : Zonahobisaya

    ReplyDelete
  13. Thank you for sharing such detailed Blog. I am learning a lot from you. Visit my website to get best Information About Best IAS Coaching in Navi Mumbai
    Best IAS Coaching in Navi Mumbai
    Top UPSC Coaching in Navi Mumbai

    ReplyDelete
  14. This blog is so cool. I am <a href="https://www.janbasktraining.com/dotnet-training>learning dot net</a> course online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!

    ReplyDelete
  15. This is very nice. Good to know about the .net and is very demanding in future. Looking for a .Net Training Services Company in Balsua? Look no further than Satyam Technology!

    ReplyDelete