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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raja TPosted Oct 12, 2015, 6:09 AM
sujit jhaPosted Oct 12, 2015, 5:50 AM
Raja TPosted Oct 12, 2015, 5:23 AM
<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)
{
}
}