More Related Content
More from Chhom Karath (20)
Chapter iii(working with data)
Editor's Notes
- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btOpen_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Text Files|*.txt";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
txt1.Text = openFileDialog1.FileName;
else
txt1.Text = "";
}
private void btSave_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
txt2.Text = saveFileDialog1.FileName;
}
private void btCopy_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt2.Text))
{
System.IO.File.Copy(txt1.Text, txt2.Text);
MessageBox.Show("The file has been successfully copied.");
}
}
private void btMove_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt1.Text))
{
MessageBox.Show("Not Found file te!");
}
else
{
System.IO.File.Move(txt1.Text, txt2.Text);
MessageBox.Show("The file has been successfully moved.");
}
}
private void btDelete_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt1.Text)) return;
if (MessageBox.Show("Are you sure you want to delete the sourcefile?", "Delete Verification",MessageBoxButtons.YesNo,MessageBoxIcon.Question)== DialogResult.Yes)
{
System.IO.File.Delete(txt1.Text);
MessageBox.Show("The file has been successfully deleted.");
}
}
private void btAttrib_Click(object sender, EventArgs e)
{
System.Text.StringBuilder stbProperties = new System.Text.StringBuilder("");
System.IO.FileAttributes fileAttributes;
stbProperties.Append("Created: ");
stbProperties.Append(System.IO.File.GetCreationTime(this.txt1.Text));
stbProperties.Append("\r\n");
stbProperties.Append("Accessed: ");
stbProperties.Append(System.IO.File.GetLastAccessTime(txt1.Text));
stbProperties.Append("\r\n");
stbProperties.Append("Modified: ");
stbProperties.Append(System.IO.File.GetLastWriteTime(txt1.Text));
fileAttributes = System.IO.File.GetAttributes(txt1.Text);
stbProperties.Append("\r\n");
stbProperties.Append("Normal: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Normal)== System.IO.FileAttributes.Normal));
stbProperties.Append("\r\n");
stbProperties.Append("Hidden: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Hidden)== System.IO.FileAttributes.Hidden));
stbProperties.Append("\r\n");
stbProperties.Append("ReadOnly: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.ReadOnly)== System.IO.FileAttributes.ReadOnly));
stbProperties.Append("\r\n");
stbProperties.Append("System: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.System)
== System.IO.FileAttributes.System));
stbProperties.Append("\r\n");
stbProperties.Append("Temporary File: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.Temporary)
== System.IO.FileAttributes.Temporary));
stbProperties.Append("\r\n");
stbProperties.Append("Archive: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.Archive)
== System.IO.FileAttributes.Archive));
txtAttrib.Text = stbProperties.ToString();
}
}
}
- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btOpen_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Text Files|*.txt";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
txt1.Text = openFileDialog1.FileName;
else
txt1.Text = "";
}
private void btSave_Click(object sender, EventArgs e)
{
Boolean b;
saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
txt2.Text = saveFileDialog1.FileName;
}
private void btCopy_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt2.Text))
{
MessageBox.Show("The source file does not exist!");
System.IO.File.Copy(txt1.Text, txt2.Text);
MessageBox.Show("The file has been successfully copied.");
}
}
private void btMove_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt1.Text))
{
MessageBox.Show("Not Found file te!");
}
else
{
System.IO.File.Move(txt1.Text, txt2.Text);
MessageBox.Show("The file has been successfully moved.");
}
}
private void btDelete_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txt1.Text)) return;
if (MessageBox.Show("Are you sure you want to delete the sourcefile?", "Delete Verification",MessageBoxButtons.YesNo,MessageBoxIcon.Question)== DialogResult.Yes)
{
System.IO.File.Delete(txt1.Text);
MessageBox.Show("The file has been successfully deleted.");
}
}
private void btAttrib_Click(object sender, EventArgs e)
{
System.Text.StringBuilder stbProperties = new System.Text.StringBuilder("");
System.IO.FileAttributes fileAttributes;
stbProperties.Append("Created: ");
stbProperties.Append(System.IO.File.GetCreationTime(this.txt1.Text));
stbProperties.Append("\r\n");
stbProperties.Append("Accessed: ");
stbProperties.Append(System.IO.File.GetLastAccessTime(txt1.Text));
stbProperties.Append("\r\n");
stbProperties.Append("Modified: ");
stbProperties.Append(System.IO.File.GetLastWriteTime(txt1.Text));
fileAttributes = System.IO.File.GetAttributes(txt1.Text);
stbProperties.Append("\r\n");
stbProperties.Append("Normal: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Normal)== System.IO.FileAttributes.Normal));
stbProperties.Append("\r\n");
stbProperties.Append("Hidden: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.Hidden)== System.IO.FileAttributes.Hidden));
stbProperties.Append("\r\n");
stbProperties.Append("ReadOnly: ");
stbProperties.Append(Convert.ToBoolean((fileAttributes & System.IO.FileAttributes.ReadOnly)== System.IO.FileAttributes.ReadOnly));
stbProperties.Append("\r\n");
stbProperties.Append("System: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.System)
== System.IO.FileAttributes.System));
stbProperties.Append("\r\n");
stbProperties.Append("Temporary File: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.Temporary)
== System.IO.FileAttributes.Temporary));
stbProperties.Append("\r\n");
stbProperties.Append("Archive: ");
stbProperties.Append(
Convert.ToBoolean((fileAttributes &
System.IO.FileAttributes.Archive)
== System.IO.FileAttributes.Archive));
txtAttrib.Text = stbProperties.ToString();
}
private void btCreateFolder_Click(object sender, EventArgs e)
{
System.IO.Directory.CreateDirectory(this.txtDir.Text );
}
private void t_Click(object sender, EventArgs e)
{
System.IO.Directory.Delete(this.txtDir.Text);
}
private void btShowDir_Click(object sender, EventArgs e)
{
MessageBox.Show(Convert.ToString(System.IO.Directory.Exists(this.txtDir.Text )));
}
private void btMoveDir_Click(object sender, EventArgs e)
{
System.IO.Directory.Move(@"D:\d",@"C:\d");
}
}
}