//---update the statusbar---
ToolStripStatusLabel1.Text = filename + ' uploaded!';
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
Deleting a Photo
To delete a photo, the user first selects a photo to delete and then you call the PerformWebRequest()
helper function you have defined earlier:
private void btnDeletePhoto_Click(object sender, EventArgs e) {
if (TreeView1.SelectedNode.ImageIndex != ico_PHOTO) {
MessageBox.Show('Please select a photo to delete.');
return;
} try {
string FullPath = Properties.Settings.Default.FTP_SERVER +
TreeView1.SelectedNode.FullPath.Substring(1).Replace('
', '');
//---delete the photo---
FtpWebResponse ftpResp =
PerformWebRequest(FullPath, WebRequestMethod.DeleteFile);
//---delete the current node---
TreeView1.SelectedNode.Remove();
//---update the statusbar---
ToolStripStatusLabel1.Text =
ftpResp.StatusDescription.Replace('
', string.Empty);
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
Once the photo is removed from the FTP server, you also need to delete its node in the TreeView
control.
Testing the Application
That's it! You can now test the application by pressing F5. Ensure that the credentials for logging in to the FTP server are correct. If the login is successful, you should be able to create a new folder on the FTP server and then upload photos. Figure 16-12 shows the complete application.

Figure 16-12
Adding Print Capability
The .NET Framework contains classes that make it easy for you to support printing in your applications. In this section, you add printing support to the PhotoViewer application so that you can print the photos. You'll explore the basics of printing in .NET and see how to configure page setup, print multiple pages, and preview a document before it is printed, as well as let users select a printer with which to print.
Basics of Printing in .NET
In .NET, all the printing functionality is encapsulated within the PrintDocument
control/class, which can be found in the Toolbox (see Figure 16-13). The PrintDocument
control defines the various methods that allow you to send output to the printer.

Figure 16-13
To incorporate printing functionality into your Windows application, you can either drag and drop the PrintDocument
control onto your form or create an instance of the PrintDocument
class at runtime. This example uses the latter approach.
To start the printing process, you use the Print()
method of the PrintDocument
class. To customize the printing process using the PrintDocument
object, there are generally three events with which you need to be acquainted:
□ BeginPrint
— Occurs when the Print()
method is called and before the first page of the document prints. Typically, you use this event to initialize fonts, file streams, and other resources used during the printing process.
□ PrintPage
— Occurs when the output to print for the current page is needed. This is the main event to code the logic required for sending the outputs to the printer.
□ EndPrint
— Occurs when the last page of the document has printed. Typically, you use this event to release fonts, file streams, and other resources used during the printing process.
Adding Print Support to the Project
To add print support to the PhotoViewer
application, first add the controls (see Figure 16- 14) in the following table.
Control | Text | Name |
---|---|---|
Label controls (2) | Print from: | |
to |