Thursday, February 4, 2010

LOGIN PAGE

for example

protected void Button1_Click(object sender, EventArgs e)
{
string lname, pword;
lname = txtlogin.Text;
pword = txtpassword.Text;
cmd = new SqlCommand("select firstname,lastname,loginname,password from user_info where loginname = @lname",conn);
cmd.Parameters.Add("lname", txtlogin.Text);
conn.Open();
dr = cmd.ExecuteReader();
dr.Read();
if (lname == dr.GetString(2).Trim() && pword == dr.GetString(3).Trim())
{
Statuslabel.Text = "You have Successfully login!!!!";
Session["firstname"] = dr.GetString(0);
Session["lastname"] = dr.GetString(1);
Response.Redirect("allinone.aspx");
}
else
{
Statuslabel.Text = "Plz,enter correct login name and password...";
}
conn.Close();
}

Retrieve the AccessControl information for this file

System.Security.AccessControl.FileSecurity sec =
File.GetAccessControl(Server.MapPath("aatish.txt"));
this.Label1.Text =
sec.GetOwner( typeof(System.Security.Principal.NTAccount) ).Value;
// retrieve the collection of access rules
AuthorizationRuleCollection auth = sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
TableCell tc;
// loop through the rule collection and add a table row for each rule
foreach (FileSystemAccessRule r in auth)
{
TableRow tr = new TableRow();
tc = new TableCell();
tc.Text = r.AccessControlType.ToString(); // deny or allow
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.IdentityReference.Value; // who
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.InheritanceFlags.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.IsInherited.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.PropagationFlags.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.FileSystemRights.ToString();
tr.Cells.Add(tc);
Table Table1=new Table();
Table1.Rows.Add(tr);//this table rows are not see to is not working
}
//Adding a rule to the Access Control List


//System.Security.AccessControl.FileSecurity sec1 =System.IO.File.GetAccessControl(Server.MapPath("aatish.txt"));
//sec1.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"Everyone",
// System.Security.AccessControl.FileSystemRights.FullControl,
//System.Security.AccessControl.AccessControlType.Allow));
//File.SetAccessControl(Server.MapPath("aatish.txt"), sec1);



//Removing a rule from the Access Control List

System.Security.AccessControl.FileSecurity sec2 = File.GetAccessControl(Server.MapPath("aatish.txt"));
sec2.RemoveAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"Everyone",
System.Security.AccessControl.FileSystemRights.FullControl,
System.Security.AccessControl.AccessControlType.Allow));
File.SetAccessControl(Server.MapPath("aatish.txt"), sec2);

how to UNZIP folder from DEFLATE function

string filename1 = Server.MapPath("aatish.zip");
FileStream infile1 = File.OpenRead(filename1);
DeflateStream deflateStream =
new DeflateStream(infile1, CompressionMode.Decompress);
byte[] buffer1 = new byte[infile1.Length + 100];
int offset = 0;
int totalCount = 0;
while (true)
{
int bytesRead = deflateStream.Read(buffer1, offset, 100);
if (bytesRead == 0)
{ break; }
offset += bytesRead;
totalCount += bytesRead;
}
FileStream outfile1 = File.Create(Path.ChangeExtension(filename1, "txt"));
outfile.Write(buffer1, 0, buffer1.Length);
outfile.Close();

how to ZIP file on hard disk.

Read the file we are going to compress into a FileStream

string filename = Server.MapPath("aatish.txt");
FileStream infile = File.OpenRead(filename);
byte[] buffer = new byte[infile.Length];
infile.Read(buffer, 0, buffer.Length);
infile.Close();


//Create the output file

FileStream outfile = File.Create(Path.ChangeExtension(filename,"zip"));

// Compress the input stream and write it to the output FileStream

GZipStream gzipStream = new GZipStream(outfile, CompressionMode.Compress);
gzipStream.Write(buffer, 0, buffer.Length);
gzipStream.Close();

How to write FIle to hard disk

FileStream fs1 = new FileStream(Server.MapPath("aatish.txt"), FileMode.Append,
FileAccess.Write, FileShare.Read);
byte[] data1 = System.Text.Encoding.ASCII.GetBytes("This is an additional string");
fs1.Write(data1, 0, data1.Length);
fs1.Flush();
fs1.Close();

how to read FIle from hard disk

FileStream fs = new FileStream(Server.MapPath("aatish.txt"), FileMode.Open);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();

This will load all directiries in all drives

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
{
TreeNode node = new TreeNode();
node.Value = drive.Name;
if (drive.IsReady)
{
node.Text = drive.Name +
" - (free space: " + drive.AvailableFreeSpace + ")";
LoadDirectories(node, drive.Name);
}
else
{
node.Text = drive.Name + " - (not ready)";
this.TreeView1.Nodes.Add(node);
}
this.TreeView1.CollapseAll();
}
}



private void LoadDirectories(TreeNode parent, string path)
{
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(path);
try
{
foreach (System.IO.DirectoryInfo d in directory.GetDirectories())
{
TreeNode node = new TreeNode(d.Name, d.FullName);
parent.ChildNodes.Add(node);
//Recurs the current directory
LoadDirectories(node, d.FullName);
}
}
catch (System.UnauthorizedAccessException e)
{
parent.Text += " (Access Denied)";
}
catch (System.IO.IOException e)
{
parent.Text += " (Unknown Error: " + e.Message + ")";
}
}