ClickOnce.

Specifically, the Windows application you build in this chapter demonstrates how to:

□ Programmatically access FTP servers using the FtpWebRequest and FtpWebResponse classes (both derived from the WebRequest and WebResponse classes in the System.Net namespace)

□ Incorporate printing capability in your Windows application using the PrintDocument class (located in the System.Drawing.Printing namespace)

□ Deploy a Windows application using ClickOnce. You will also see how to programmatically cause an application to update itself.

The Project

The project in this chapter is a photo viewer Windows application that accesses an FTP server. Using this application, users can upload photos to an FTP server and also download and view images stored on the FTP server. The application is useful for companies that may need to access images uploaded by their partners. Insurance companies, for instance, may need to access photographs of car damage taken by auto body shop mechanics to facilitate estimating the cost of repair. Rather than build a complex web application, the shops and insurance companies can simply use this application to quickly upload and view photos. Users can also print the photos directly from the application.

Figure 16-1 shows how the application will look like when it is completed.

Figure 16-1

Configuring the FTP Server

Before you start writing the code of this application, you first need to configure FTP service for your computer. For this project, use the FTP service on your development machine.

By default, FTP service is not installed in Windows (note that FTP service is not available on Windows Vista Home editions). To add FTP Service to your computer, select Control Panel→Add or Remove Programs. Click the Add/Remove Windows Component tab, select Internet Information Services (IIS), and click the Details button. Select File Transfer Protocol (FTP) Service, and click OK.

To configure the FTP service on your computer, launch the Internet Information Services management console window by typing the command inetmgr in the Run window. Your FTP site should look like Figure 16-2.

Figure 16-2

Right-click the Default FTP Site item, and select Properties. Click the Security Accounts tab. Ensure that the Allow Anonymous Connections checkbox is checked (see Figure 16-3) to enable an anonymous user to log in to your FTP service.

Figure 16-3

Next, click on the Home Directory tab, and check the Write checkbox (see Figure 16-4). This allows users to your FTP service to upload files and create directories on the FTP server.

Figure 16-4

Click OK to finish the configuration of the FTP service.

Creating the Application

Using Visual Studio 2008, create a new Windows application and name it PhotoViewer. Populate the default Form1 with the controls shown in Figure 16-5. These controls are:

Control Text Name
Button controls (4) Create Folder btnCreateFolder
Remove Folder btnRemoveFolder
Upload Photos btnUploadPhotos
Delete Photo btnDeletePhoto
GroupBox controls (3) FTP Server  
Folders  
Photos  
Label controls (6) Server Name/IP
Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату