See,
string filename="test.zip";
string path=MapPath("~/soft/" + filename);
byte []bts=System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeader();
Response.AddHeader("Content-Type","Application/octet-stream")
Response.AddHeader("Content-Length",bts.Length.ToString());
Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Please correct it : Response.ClearHeaders()
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
You must have to read those links which I have posted in your previous thread. You need to handle the event of GridView control.
Markup
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("url") %>' CommandName="cmd">Download</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-behind
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmd")
{
string filename=e.CommandArgument.ToString();
string path=MapPath("~/soft/" + filename);
byte []bts=System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "Application/octet-stream");
Response.AddHeader("Content-Length",bts.Length.ToString());
Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
}
}
PS: Try to mark thread as solved if you have found an answer to your question.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
You must have to read those links which I have posted in your previous thread. You need to handle the event of GridView control.
Markup
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("url") %>' CommandName="cmd">Download</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-behind
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmd")
{
string filename=e.CommandArgument.ToString();
string path=MapPath("~/soft/" + filename);
byte []bts=System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "Application/octet-stream");
Response.AddHeader("Content-Length",bts.Length.ToString());
Response.AddHeader("Content-Disposition","attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
}
}
PS: Try to mark thread as solved if you have found an answer to your question.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
You're welcome.
I'm glad you got it working.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241