Hour 19. Performing File Operations wax ka badal

It's very difficult to imagine any application other than a tiny utility program that doesn't make use of the file system. In this hour, you'll learn how to use the controls to make it easy for a user to browse and select files. In addition, you'll learn how to use the System.IO.File and System.IO.Directory objects to manipulate the file system. Using these objects, you can delete files and directories, move them, rename them, and more. These objects are powerful, but please remember: play nice!

The highlights of this hour include the following:

  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch19lev1sec1.htm#ch19lev1sec1 Using the Open File Dialog and Save File Dialog controls]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch19lev1sec2.htm#ch19lev1sec2 Manipulating files with System.IO.File]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch19lev1sec3.htm#ch19lev1sec3 Manipulating directories with System.IO.Directory]

>

Using the Open File Dialog and Save File Dialog Controls

In [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch01.htm#ch01 Hour 1], "A C# Programming Tour," you used the Open File Dialog control to enable a user to browse for pictures to display in your Picture Viewer program. In this section, you'll move beyond those basics to learn important details about working with the Open File Dialog control, as well as its sister control, the Save File Dialog.

You're going to build a project to illustrate most of the file-manipulation concepts discussed in this hour. Before continuing, create a new Windows Application titled Manipulating Files. Change the name of the default form to fclsManipulatingFiles, set its Text to Manipulating Files, and then set the entry point of the project to fclsManipulatingFiles. Add a new text box to the form and set its properties as shown in the following table:

Property Value
Name txtSource
Location 95,8
Size 184,20
Text (make blank)
Using the Open File Dialog Control 

The Open File Dialog control is used to display a dialog box that enables the user to browse and select a file (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig01 Figure 19.1]). It's important to note that usually the Open File Dialog doesn't actually open a file, but it allows a user to select a file that is then opened by code within the application.

Figure 19.1. The Open File dialog box is used to browse and select files.

graphics/19fig01.jpg

Add a new Open File Dialog to your project now by double-clicking the OpenFileDialog item in the toolbox. The Open File Dialog doesn't have an interface per se, so it appears in the area below the form rather than on it. For the user to browse for files, you have to manipulate the Open File Dialog using its properties and methods.

You're going to add a button to the form that, when clicked, allows a user to locate and select a file. If a user selects a file, the filename will be placed in the text box you've created. Go ahead and add a button to the form now, and set its properties as follows:

Property Value
Name btnOpenFile
Location 8,8
Size 80,23
Text Source

Next, double-click the button and add the following code to its Click event:

openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Select a File";

The first statement specifies the directory to display when the dialog box is first shown. If you don't specify a directory for the InitialDirectory property, the active system directory is used (for example, the last directory browsed to with a different Open File dialog box).

The Title property of the Open File Dialog determines the text displayed in the title bar of the Open File dialog box. If you don't specify text for the Title property, C# displays the word Open in the title bar.

Different types of files have different extensions. The Filter property determines what types of files appear in the Open File dialog box (refer to [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig01 Figure 19.1]). A filter is specified in the following format:

Description|*.extension 

The text that appears before the pipe symbol (|) is the descriptive text of the file type to filter on, whereas the text after the pipe symbol is the pattern used to filter files. For example, to display only Windows bitmap files, you could use a filter such as the following:

control.Filter = "Windows Bitmaps|*.bmp";

You can specify more than one filter type. To do this, add a pipe symbol (|) between the filters, like this:

control.Filter = "Windows Bitmaps|*.bmp|JPEG Files|*.jpg";

You're going to restrict your Open File dialog box to show only text files, so enter the following statement in your btnOpenFile_Click code:

openFileDialog1.Filter = "Text Files|*.txt";

When you have more than one filter, you can specify which filter appears selected by default using the FilterIndex property. Although you've specified only one filter type in this example, it's still a good idea to designate the default filter, so add this statement to your code:

openFileDialog1.FilterIndex = 1;

Finally, you need to show the Open File dialog box and take action based on whether the user selects a file. The ShowDialog() method of the Open File Dialog control acts much like the method of forms by the same name, returning a result that indicates the user's selection on the dialog box. Enter the following statements into your procedure:

if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
 txtSource.Text = openFileDialog1.FileName;
else
 txtSource.Text = "";

This code just places the selected filename into the text box txtSource. If the user clicks Cancel, the contents of the text box are cleared.

Press F5 to run the project and click the button. You'll get the same dialog box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig01 Figure 19.1] (with different files and directories, of course). Select a text file, click Open, and C# places the name of the file into the text box.

graphics/bulb.gif By default, the Open File Dialog won't allow the user to enter a filename that doesn't exist. You can override this behavior by setting the CheckFileExists property of the Open File Dialog to false.
graphics/bookpencil.gif The Open File Dialog control has the capability to allow the user to select multiple files. It's rare that you need to do this (I don't recall ever needing this capability in one of my projects), so I won't go into the details here. If you're interested, take a look at the Multiselect property of the Open File Dialog in the Help text.

The Open File Dialog control makes allowing a user to browse and select a file almost trivial. Without this code, you would have to write an amazing amount of very difficult code and would still probably not come up with all the functionality supported by this control.

 Using the Save File Dialog Control 

The Save File Dialog control is very similar to the Open File Dialog control, but it is used to allow a user to browse directories and specify a file to save, rather than open. Again, it's important to note that the Save File Dialog doesn't actually save a file, it is used to enable a user to specify a file to save; you'll have to write code to do something with the filename returned by the control.

You're going to use the Save File Dialog to let the user specify a filename. This filename will be the target of various file operations you'll learn about later in this hour. Create a new text box on your form and set its properties as follows:

Property Value
Name txtDestination
Location 95,40
Size 184,20
Text (make blank)

You're now going to create a button that, when clicked, enables the user to specify a filename to save a file. Add a new button to the form and set its properties as shown in the following table:

Property Value
Name btnSaveFile
Location 8,40
Size 80,23
Text Destination

Of course, none of this will work without adding a Save File dialog box. Double-click the SaveFileDialog item in the toolbox to add a new control to the project.

Next, double-click the new button (btnSaveFile) and add the following code to its Click event:

saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;

The first three statements set properties that are identical to those of the Open File Dialog. The OverwritePrompt property, however, is unique to the Save File Dialog. When this property is set to true, C# asks users to confirm their selections when they choose a file that already exists, as shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig02 Figure 19.2]. I highly recommend that you prompt the user about replacing files by ensuring the OverwritePrompt property is set to true.

Figure 19.2. It's a good idea to get confirmation before replacing an existing file.

graphics/19fig02.jpg

graphics/bookpencil.gif If you want the Save File dialog box to prompt users when the file they specify doesn't exist, set the CreatePrompt property of the Save File Dialog control to true.

The last bit of code you need to add places the selected filename in the txtDestination text box. Enter the code as shown here:

if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
 txtDestination.Text = saveFileDialog1.FileName;

Press F5 to run the project. Then click each of the buttons and select a file. When you're satisfied that your selections are being sent to the appropriate text box, stop the project and save your work. If your selected filenames aren't being sent to the proper text box, verify that your code is correct.

The Open File Dialog and Save File Dialog controls are very similar in their design and appearance, but each serves a specific purpose. Throughout the rest of this hour, you'll be using the interface you've just created.

Manipulating Files with the File Object 

.NET includes a powerful object called System.IO (technically, System and IO are Namespaces, but they behave like objects). Using various properties, methods, and object properties of System.IO, you can do just about anything you can imagine with the file system. In particular, the System.IO.File and System.IO.Directory objects provide you with extensive file and directory (folder) manipulation.

In the following sections, you'll continue to expand the project that you created earlier in this hour. You'll be writing code that manipulates the filenames selected using the Open File Dialog and Save File Dialog controls.

graphics/bookpencil.gif The code you'll write in the following sections is "the real thing." For instance, the code for deleting a file really deletes a file. Don't forget this as you test your project; the files selected as the source and as the destination will be affected by your actions. I provide the cannon; it's up to you not to shoot yourself in the foot.
Determining Whether a File Exists 

Before attempting any operation on a file, such as copying or deleting it, it's a good idea to make certain the file exists. For example, if the user doesn't click the Source button to select a file but types the name and path of a file into the text box instead, the user could type an incorrect filename. Attempting to manipulate a nonexistent file could result in an exception, which you don't want to happen. Because you're going to work with the source file selected by the user in many routines, you're going to write a central function that can be called to determine whether the source file exists. The function uses the Exists() method of the System.IO.File object to determine whether the file exists.

Add the following method to your Form class:

bool SourceFileExists()
{
if (!System.IO.File.Exists(txtSource.Text))
 {
 MessageBox.Show("The source file does not exist!");
 return false;
 }
 else
 return true;
}

The Exists() method accepts a string containing the filename (with path) of the file to verify. If the file exists, Exists() returns true; otherwise, it returns false.

 Copying a File 

Copying files is a common task. For instance, you may want to create an application that backs up important data files by copying them to another location. For the most part, copying is pretty safe�as long as you specify a destination filename that doesn't already exist. Copying files is accomplished using the Copy() method of the System.IO.File object.

You're now going to add a button to your form. When the user clicks this button, the file specified in the source text box will be copied to a new file with the name given in the destination text box. Add a button to your form now and set its properties as shown in the following table:

Property Value
Name btnCopyFile
Location 96,80
Size 75,23
Text Copy

Double-click the Copy button and add the following code:

if (!SourceFileExists()) return;
System.IO.File.Copy(txtSource.Text, txtDestination.Text);
MessageBox.Show("The file has been successfully copied.");

The Copy() method has two arguments. The first is the file that you want to copy, and the second is the name and path of the new copy of the file. In this example, you're using the filenames in the two text boxes.

Press F5 to run the project and test your copy code now by following these steps:

  1. Click the Source button and select a text file.
  2. Click the Destination button to display the Save File dialog box. Don't select an existing file. Instead, type a new filename into the File Name text box and click Save. If you are asked whether you want to replace a file, click No and change your filename; don't use the name of an existing file.
  3. Click Copy to copy the file.

After you get the message box telling you the file was copied, you can use Explorer to locate the new file and open it. Stop the project and save your work before continuing.

 Moving a File 

When you move a file, the file is taken out of its current directory and placed into a new one. You can specify a new name for the file or use the original name. Moving a file is accomplished with the Move() method of the System.IO.File object. You're now going to create a button on your form that will move the file selected as the source to the path and the filename selected as the destination.

graphics/bulb.gif I recommend that you use Notepad to create a text file and then use this temporary text file when testing this code and the rest of the examples that permanently alter or destroy a file.

Add a new button to the form and set its properties as follows:

Property Value
Name btnMove
Location 96,112
Size 75,23
Text Move

Double-click the Move button and add the following code to its Click event:

if (!SourceFileExists()) return;
System.IO.File.Move(txtSource.Text, txtDestination.Text);
MessageBox.Show("The file has been successfully moved.");

Remember, if you specify a name for the destination that isn't the same as that of the source, the file will be given the new name when it's copied.

 Deleting a File 

Deleting a file can be a risky proposition. The Delete() method of System.IO.File deletes a file permanently�it doesn't send the file to the Recycle Bin. For this reason, you should take great care when deleting files. First and foremost, this means testing your code. When you write a routine to delete a file, be sure to test it under various conditions. For example, if you mistakenly referenced the destination text box instead of the source text box in this project, you could inadvertently delete the wrong file! Users aren't forgiving of such mistakes.

You're now going to add a button to your project that deletes the source file when clicked. Remember, be careful when testing this code. Add a button to the form now and set its properties as follows:

Property Value
Name btnDelete
Location 96,144
Size 75,23
Text Delete

Next, double-click the button and add the following code to its Click event:

if (!SourceFileExists()) return;

if (MessageBox.Show("Are you sure you want to delete the source file?", "Delete 
[[Image:ccc.gif|18px|graphics/ccc.gif]]Verification",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
 System.IO.File.Delete(txtSource.Text);
 MessageBox.Show("The file has been successfully deleted.");
}

Notice that you've included a message box to confirm the user's intentions. It's a good idea to do this whenever you are about to perform a serious action that can't be undone. In fact, the more information you can give, the better. For example, I would suggest that if this were production code (code meant for end users) that you include the name of the file in the message box, so the user knows without a doubt what the program intends to do.

 Renaming a File 

When you rename a file, it remains in the same directory and nothing materially happens to the contents of the file�the name is changed to something else. Because the original file isn't altered, renaming a file isn't as risky as performing an action such as deleting the file. Nevertheless, it is frustrating trying to determine what happened to a file when it was mistakenly renamed. To rename a file, use the Move() method of System.IO.File, specifying a new filename but keeping the same path.

 Retrieving a File's Properties 

Although many don't realize it, files have a number of properties, such as the date the file was last modified. The easiest way to see these properties is to use Explorer. View the attributes of a file now by starting Explorer, right-clicking any file displayed in Explorer, and choosing Properties. Explorer then shows the File Properties window with information about the file (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig03 Figure 19.3]).

The System.IO.File object provides ways to get at most of the data displayed on the General tab of the File Properties dialog box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig03 Figure 19.3]. Some of this data is available directly from the File object, whereas others are accessed using a FileAttributes object.

 Getting Date and Time Information About a File 

Getting the last created, last accessed, and last modified dates of a file is easy; the System.IO.File object supports a method for each of these dates. [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19table01 Table 19.1] lists the applicable methods and what they return.

Property Description
GetCreationTime Returns the date and time the file was created.
GetLastAccessTime Returns the date and time the file was last accessed.
GetLastWriteTime Returns the date and time the file was last modified.
Getting the Attributes of a File 

The attributes of a file (refer to the bottom of the dialog box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig03 Figure 19.3]) aren't available as properties or methods of the System.IO.File object. Just how you determine an attribute's value is a bit complicated. The GetAttributes() method of System.IO.File returns a FileAttributes enumeration. This, in turn, acts as a set of flags for the various attributes. The method used to store these values is called bit packing. Bit packing is pretty complicated and has to do with the binary method in which values are stored in memory and on disk. Teaching bit packing is beyond the scope of this book�what I want to show you is how to determine if a certain flag is set in a value that is bit packed.

The first step to determining the attributes is to get the file attributes. To do this, create a FileAttributes variable and call GetAttributes(), like this:

System.IO.FileAttributes objfileAttributes ;
lngAttributes = System.IO.File.GetAttributes(txtSource.Text);

After you have the flags in the variable, by &ing the variable with one of the flags shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19table02 Table 19.2] and then testing whether the result equals the flag, you can determine whether a particular attribute is set. For example, to determine whether a file's ReadOnly flag is set, you could use a statement like the following:

(objfileAttributes &
 System.IO.FileAttributes.ReadOnly == System.IO.FileAttributes.ReadOnly)

When you & a flag value with a variable, you'll get the flag value back if the variable contains the flag; otherwise, you'll get a zero back.

Attribute Meaning
Archive The file's archive status. Applications use this attribute to mark files for backup and removal.
Directory The file is a directory.
Hidden The file is hidden and therefore not included in an ordinary directory listing.
Normal The file is normal and has no other attributes set.
ReadOnly The file is a read-only file.
System The file is part of the operating system or is used exclusively by the operating system.
Temporary The file is a temporary file.
Writing Code to Retrieve a File's Properties 

Now that you know how to retrieve the properties of an object, you're going to use this knowledge to display the properties of the file specified in the source text box on your form. Begin by adding a new button to your form and setting its properties as shown in the following table:

Property Value
Name btnGetFileProperties
Location 8,176
Size 80,56
Text Get Properties of Source File

Next, add a text box to the form and set its properties as follows:

Property Value
Name txtProperties
Location 96,176
Multiline True
ScrollBars Vertical
Size 184,88
Text (make blank)

The code you enter into the Click event of the button will be a bit longer than most of the code you've entered so far. Therefore, I'll show the code in its entirety, and then I'll explain what the code does. Double-click the button and add the following code to the button's Click event:

System.Text.StringBuilder stbProperties = new System.Text.StringBuilder("");
System.IO.FileAttributes fileAttributes ;

if (!SourceFileExists()) return;
// Get the dates.
stbProperties.Append("Created: ");
stbProperties.Append(System.IO.File.GetCreationTime(txtSource.Text));

stbProperties.Append("\r\n");

stbProperties.Append("Accessed: ");
stbProperties.Append(System.IO.File.GetLastAccessTime(txtSource.Text));

stbProperties.Append("\r\n");

stbProperties.Append("Modified: ");
stbProperties.Append(System.IO.File.GetLastWriteTime(txtSource.Text));

// Get File Attributes
fileAttributes = System.IO.File.GetAttributes(txtSource.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));

txtProperties.Text = stbProperties.ToString();

All the various properties of the file are appended to the StringBuilder variable stbProperties. The "\r\n" denotes a carriage return and a linefeed, and appending this into the string ensures that each property appears on its own line.

The first statement declares an empty StringBuilder variable called stbProperties. The StringBuilder object was designed for optimizing string concatenation. You'll be using the append method of the StringBuilder class to create the file properties text. The second set of statements simply call the GetCreateTime(), GetLastAccessTime(), and GetLastWriteTime() methods to get the values of the date-related properties. Next, the attributes are placed in a variable by way of the GetAttributes() method, and the state of each attribute is determined. The Convert.ToBoolean() method is used so that the words True and False appear. Lastly, you assign the txtProperties.Text value to the created StringBuilder string.

graphics/bookpencil.gif You've previously used the + to concatenate strings, and this will also work. But, when concatenating a large number of strings, you should use the StringBuilder object. The reason for this is that strings are immutable in .NET�they can never be changed. So every concatenation operation creates an entirely new string object, discarding both of the other strings. This can have a negative affect on performance.

Press F5 to run the project, click Source to select a file, and then click the button to get and display the attributes. If you entered the code exactly as shown, the attributes of the file should appear in the text box as they do in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#ch19fig04 Figure 19.4].

Figure 19.4. The System.IO.File object enables you to look at the properties of a file.

graphics/19fig04.jpg

Manipulating Directories with the Directory Object

Manipulating directories (folders) is very similar to manipulating files. However, rather than using System.IO.File, you use System.IO.Directory. Notice that when you specify a directory path, double slashes are used instead of just one. If any of these method calls confuse you, see the previous section on System.IO.File for more detailed information. Following are the method calls:

  • To create a directory, call the CreateDirectory() method of System.IO.Directory, passing the name of the new folder, like this: (Note: As discussed in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch12.htm#ch12 Hour 12], you must preference literal strings containing slashes with the @ character.)
System.IO.Directory.CreateDirectory(@"c:\my new directory");
  • To determine whether a directory exists, call the Exists() method of System.IO.Directory, passing it the directory name in question, like this:
MessageBox.Show(Convert.ToString(System.IO.Directory.Exists(@"c:\temp")));
  • To move a directory, call the Move() method of System.IO.Directory. The Move() method takes two arguments. The first is the current name of the directory, and the second is the new name and path of the directory. When you move a directory, the contents of it are moved as well. The following illustrates a call to Move().
System.IO.Directory.Move(@"c:\current directory name",
 @"d:\new directory name");
  • Deleting directories is even more perilous than deleting files; when you delete a directory, you also delete all files and subdirectories within the directory. To delete a directory, call the Delete() method of System.IO.Directory, passing it to the directory to delete. I can't tell you often enough that you have to be careful when calling this method; it can you get you into a lot of trouble. The following statement illustrates deleting a directory:
System.IO.Directory.Delete(@"c:\temp");
>

Summary

The Open File Dialog and Save File Dialog controls coupled with System.IO enable you to do many powerful things with a user's file system. In this hour, you learned how to let a user browse and select a file for opening, and how to let a user browse and select a file for saving. Determining a user's file selection is only the first part of the process, however. You also learned how to manipulate files and directories, including renaming, moving, and deleting, by using System.IO. Finally, you learned how to retrieve the properties and attributes of a file.

With the techniques shown in this hour, you should be able to do most of what you'll need to do with files and directories. None of this material is very difficult, but don't be fooled by the simplicity; use care whenever manipulating a user's file system.

>

Q&A

[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#qad1e59343 Q1:] What if I want to perform an operation on a file, but something is preventing the operation, such as the file may be open or I don't have rights to the file?
A1: All the method calls have one or more exceptions that can be thrown in the event that the method fails. These method calls are listed in the online Help. You can use the techniques discussed in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch16.htm#ch16 Hour 16], "Debugging Your Code," to trap the exceptions.
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/19.htm#qad1e59359 Q2:] What if a user types a filename into one of the file dialog boxes, but the user doesn't include the extension?
A2: By default, both file dialog controls have their AddExtension properties set to true. When this property is set to true, C# automatically appends the extension of the currently selected filter.
>

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and get you thinking about how to put your knowledge into practice. The answers to the quiz are in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01.htm#app01 Appendix A], "Answers to Quizzes/Exercises."

 Quiz
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans01 1:] True or False: The Open File dialog box automatically opens a file.
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans02 2:] What symbol is used to separate a filter description from its extension?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans03 3:] What objects are used to manipulate files?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans04 4:] What arguments are required by System.IO.File.Copy()?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans05 5:] How would you rename a file?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans06 6:] True or False: Files deleted with System.IO.File.Delete() are sent to the Recycle Bin.
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec19.htm#ch19ans07 7:] What objects are used to manipulate folders?
 Exercises
  1. Create a project that enables a user to select a file with the Open Dialog control. Store the filename in a text box. Provide another button that, when clicked, creates a backup of the file by making a copy of it with the extension .bak.
  2. Create a project with a text box on it in which the user can type in a three-character file extension. Include a button that, when clicked, shows an Open File dialog box with the filter set to the extension entered by the user.