protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Download") { byte[] byteimg = null; byte[] byteimg1 = null; bool replica = false; GridViewRow gvrow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer; string id = gvrow.Cells[0].Text; string servername = gvrow.Cells[2].Text; string filename = gvrow.Cells[1].Text; string f1=filename.Replace(' ', '_'); string ext = Path.GetExtension(filename); Random rnd = new Random(); int random = rnd.Next(0, 9); if (servername == "S1") { if (random == 0 || random == 6 || random == 9 || random == 3 || random == 1 || random == 7) { ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Server has been crashed.. ');", true); byteimg1 = db.getbytesreplica1(id); replica = true; } else { byteimg = db.getbytes1(id); } } else if (servername == "S2") { byteimg1 = db.getbytesreplica2(id); byteimg = db.getbytes2(id); } else if (servername == "S3") { byteimg1 = db.getbytesreplica3(id); byteimg = db.getbytes3(id); } else { byteimg1 = db.getbytesreplica4(id); byteimg = db.getbytes4(id); } if (ext == ".pdf") { Response.ContentType = "application/pdf"; } else if (ext == ".doc" || ext == ".rtf" || ext == ".docx") { Response.ContentType = "Application/msword"; } else if (ext == ".txt") { Response.ContentType = "text/Plain"; } else if (ext == ".rar") { Response.ContentType = "Application/x-rar-compressed"; } else if (ext == ".jpeg" || ext == ".jpg") { Response.ContentType = "image/jpeg"; divmsg.InnerHtml = "asd"; } else if (ext == ".png") { Response.ContentType = "image/png"; } else { Response.ContentType = "Application/octetstream"; } popup.Show(); Response.AddHeader("Content-disposition", "attachment; filename=" + f1); // Response.AppendHeader("Content-disposition", filename.ToString()); if (replica) { Response.BinaryWrite(byteimg1); } else { Response.BinaryWrite(byteimg); } Response.Flush(); Response.End(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)