Above is the WinForm form I created, the pull control is so, GroupBox displays information about the file
The code is as follows:
Class object for the Instantiate file dialog box
OpenFileDialog Ofg = new OpenFileDialog ();
Store source file path, one destination file path
string filepath;
String filepath1;
Get File Object
FileInfo file = null;
private void Button1_Click (object sender, EventArgs e)
{
function that invokes an object
if (Ofg. ShowDialog () = = DialogResult.OK) {
Get the path to the file
filepath = Ofg. FileName;
This.txb_Path1.Text = filepath;
To create a file object
File = new FileInfo (filepath);
Get file name
This.txtFileName.Text = file. Name;
Get file Full path
This.txtFilePathAll.Text = file. FullName;
Get the root directory where the files are located
This.txtFileRoot.Text = file. DirectoryName;
This.txtCreatetime.Text = file. Creationtime.tostring ();
This.txtVisttime.Text = file. Lastaccesstime.tostring ();
This.txtUpdatetime.Text = file. Lastwritetime.tostring ();
}
}
private void Button2_Click (object sender, EventArgs e)
{
Get file directory
FolderBrowserDialog fog = new FolderBrowserDialog ();
if (fog. ShowDialog () = = DialogResult.OK)
{
Get Storage directory (folder)
Filepath1 = fog. SelectedPath;
This.txb_Path2.Text = filepath1;
}
}
private void Button3_Click (object sender, EventArgs e)
{
filepath1 = [email protected] "\" + file. Name;
File.Copy (FILEPATH,FILEPATH1);
MessageBox.Show ("Copy succeeded! ");
}
The results are as follows:
How to open a file dialog box with C # and a simple program to use