using System.IO;
public partial class download : System.Web.UI.Page
{
string filepath = "~/DataFile/";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
public string file()
{
SqlCommand cmd = new SqlCommand("select FileName from registation where username='" + Session["uname"].ToString() + "'", con);
con.Open();
string fi_Name = cmd.ExecuteScalar().ToString();
con.Close();
return fi_Name;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] != null)
{
Label1.Text = "Welcome" + Session["uname"].ToString();
}
else{
Response.Redirect("userlogin.aspx");
}
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/DataFile/"));
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fi2 in fi)
{
if (file() == fi2.Name)
{
Response.ContentType = "application/pdf||.doc";
Response.WriteFile(fi2.FullName);
}
}
No comments:
Post a Comment