Download
How can ritrive and read and download .txt file in asp.net. Actually i have ritrive text but i cant download that file .
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Raja TRank #685 · 3.5K reputationPosted Oct 12, 2015, 1:23 AM EDT
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td style="text-align: right">Select Path :- td>
<td><asp:TextBox ID="txtFileName" runat="server" Width="201px">asp:TextBox>td>
tr>
<tr>
<td> td>
<td> td>
tr>
<tr>
<td> 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)
{
}
}
sujit jha77 reputationPosted Oct 12, 2015, 1:50 AM EDT
Raja TRank #685 · 3.5K reputationPosted Oct 12, 2015, 2:09 AM EDT