How to open a file dialog box with C # and a simple program to use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.