protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { try { string fileName = ((Label)GridView1.Rows[e.NewSelectedIndex].FindControl("lnkFileName")).Text; Session["fileopen"] = fileName; string path = GetPath() + fileName; FileInfo file = new FileInfo(path); if (file.Exists) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlDatabase"].ConnectionString); con.Open(); cmd = new SqlCommand("select * from FileTypes with(nolock) where extension='" + file.Extension + "'", con); cmd.CommandTimeout = 0; myReader = cmd.ExecuteReader(); cmd.CommandTimeout = 0; if (myReader.Read()) { myReader.Close(); SessionVarriables.ViewFileSession = path; SessionVarriables.ViewFileNameSession = "File"; Response.Redirect("ViewDocument.aspx"); } else { myReader.Close(); Message1("Cannot open selected file"); return; } con.Close(); } else { Message1("File not found"); } } catch (Exception ex) { UserUtil.Message(ex.Message, this); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)