0% found this document useful (0 votes)
28 views

Using Using Using Using Using Using Using Using Using Using Using Using Public Partial Class Protected Void Object If New

This document contains the code for a C# ASP.NET web page that performs several file operations. It loads image file names from a directory into dropdown and list boxes. It authenticates users by querying a database. It allows viewing selected images, uploading new images, writing comments to a text file, and deleting selected images.

Uploaded by

neeraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Using Using Using Using Using Using Using Using Using Using Using Using Public Partial Class Protected Void Object If New

This document contains the code for a C# ASP.NET web page that performs several file operations. It loads image file names from a directory into dropdown and list boxes. It authenticates users by querying a database. It allows viewing selected images, uploading new images, writing comments to a text file, and deleting selected images.

Uploaded by

neeraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DirectoryInfo d = new
DirectoryInfo(Server.MapPath("photo"));
FileInfo[] files = d.GetFiles();
for (int i = 0; i < files.Length; i++)
{
DropDownList1.Items.Add(files[i].Name);
ListBox1.Items.Add(files[i].Name);
}
}
}
protected void btn1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=(local);Initial
Catalog=company;Integrated Security=True;";
con.Open();
SqlCommand cmd = new SqlCommand("select * from login where
username=@name and password=@password",con);
cmd.Parameters.Add(new SqlParameter("@name",tb1.Text));
cmd.Parameters.Add(new SqlParameter("@password", tb2.Text));
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
status.Text = "you are a valid user!";
}
else
{
status.Text = "you are not a valid user!";

}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Panel1.Visible = true; //
Response.Redirect("http://www.google.com");
}
protected void Button1_Click(object sender, EventArgs e)
{
File.WriteAllText(Server.MapPath("comment.txt"),TextBox1.Text);
Panel1.Visible = false;
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
Image1.ImageUrl =
Server.MapPath("photo/"+DropDownList1.SelectedValue);
}
protected void Button2_Click(object sender, EventArgs e)
{

FileUpload1.SaveAs(Server.MapPath("photo/"+FileUpload1.FileName));
DropDownList1.Items.Add(FileUpload1.FileName);
}
protected void Button3_Click(object sender, EventArgs e)
{
File.Delete(Server.MapPath("Photo/"+ListBox1.SelectedValue));
}
}

You might also like