<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" onrowcommand="GridView1_RowCommand" DataKeyNames="DocID" Height="50px" Width="50px" AllowSorting="True"> <Columns> <asp:BoundField DataField="DocID" HeaderText="DocID" InsertVisible="False" ReadOnly="True" SortExpression="DocID" Visible="False" /><asp:ButtonField ButtonType="Image" ImageUrl="~/download-button.jpg" CommandName="Download" HeaderText="Download" ControlStyle-Height="20px" ControlStyle-Width="20px" > <ControlStyle Height="20px" Width="20px"></ControlStyle> </asp:ButtonField> </Columns> </asp:GridView>
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Download") { string fileName = string.Empty; int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView2.Rows[index]; int documentID = Convert.ToInt32(GridView2.DataKeys[index].Value); SqlConnection con = new SqlConnection("Server=.;Database=E_Notes;integrated Security=true"); //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT DocName FROM SaveDoc WHERE DocID = " + documentID, con); con.Open(); SqlDataReader dReader = cmd.ExecuteReader(); while (dReader.Read()) { fileName = dReader["DocName"].ToString(); byte[] documentBinary = (byte[])dReader["DocData"]; FileStream fStream = new FileStream(Server.MapPath("../Docs/") + @"\" + fileName, FileMode.Create); fStream.Write(documentBinary, 0, documentBinary.Length); fStream.Close(); fStream.Dispose(); } con.Close(); Response.Redirect(@"..\Docs\" + fileName); } }
http://stackoverflow.com/a/8994342[^]You can't is the short answer. The browser is the only thing that can open up a new window. What you can do is send a chunk of html down the response that has a link with your url as an href, target="_blank" and a chunk of javascript onload of the form that fakes a click. If this doesn't work then use a window.open(url); C# response.write("<script>"); response.write("window.open('page.html','_blank')"); response.write("</script>");
response.write("<script>"); response.write("window.open('page.html','_blank')"); response.write("</script>");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)