Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

SmartClient with Visual Studio 2005

Nowadays, it is very common to have intranets in the companies, either to publish corporative sites and portals or to simply share files and tasks.

SmartClient with Visual Studio 2005

  

Nowadays, it is very common to have intranets in the companies, either to publish corporative sites and portals or to simply share files and tasks. But can we use these intranets in an even more efficient way, as for example, to distribute our internal applications or who knows to make applications available for our customers through our corporative site?

 

You must be thinking that we are talking about some web application, since these applications are widely published in the corporative intranets and extranets.

 

But what if I need to have a richer application, with a faster and more efficient interface than a web application? I would have to create this Windows application and also an efficient installation and distribution mechanism, place links for the users to download and install in their computers, that is, it would be a lot of trouble.

 

In this scenario the concept of SmartClient and ClickOnce comes in, who as we are used to saying: “is the best of both worlds”, that is, you have the richness of a Windows application and the distribution facility of a web application.

 

So imagine being able to create your corporative application and place it in your intranet, where the user will simply click a HTML page and the application will be installed automatically in his computer. And also any modification, which occurs in the application, at the next call the user makes, the application will automatically be updated. That is what we will see now!

 

Creating a Windows Forms application

We will create a very simple windows forms application. This application will not do anything special, besides having some Windows controls. For this example you can also work with an application of your own made in Visual Studio 2005. To begin, create a new Windows project in Visual Studio 2005, according to Figure 1. After creating the project, place a button and a ListBox, as shown in Figure 2.

 

cdscwvsfig01.jpg 

Figure 1. Creating a Windows Forms project in Visual Studio 2005.

 

cdscwvsfig02.jpg 

Figure 2. Windows Application with controls.

 

Adding a functionality to the application

In order for us to test our SmartClient, we will add a code for access to the Northwind database, which is part of the default installation of the SQL Server 2000, and we will return the names of all the products in the Products table. This can be done by adding the code in Listing 1, relative to the event Click of the button (pay attention to the namespaces, added at the using).

 

For the example, we have created the connection with the database and have used a SqlCommand and SqlDataReader in order to read the data and fill in the ListBox.

 

Listing 1. Gaining access to the database and filling in the ListBox

using System.Data.SqlClient;

...

   private void button1_Click(object sender,

     EventArgs e)

   {

      SqlConnection conn = new SqlConnection(

        "data source=(local); initial catalog="+

        "northwind; integrated security=true;");

      SqlCommand cmd = new SqlCommand(

        "select productname from products", conn);

      SqlDataReader dr = null;

 

      listBox1.Items.Clear();

      try

      {

         conn.Open();

         dr = cmd.ExecuteReader();

         while (dr.Read())

         {

             listBox1.Items.Add(

               dr["productname"].ToString());

         }

       }

       catch (Exception ex)

       {

          MessageBox.Show("Error: "+

            ex.Message);

       }

       finally

       {

          dr.Close();

          conn.Close();

       }

     }

   }

}

 

Transforming the application into a SmartClient

Now comes the most interesting part, we are going to take our Windows application and publish it in the intranet or the internet so that everyone can access it. For this, we will use Visual Studio publication feature (publish), through the Build>Publish menu (Figure 3).

 

cdscwvsfig03.jpg 

Figure 3. Publishing the application through the ClickOnce.

 

Clicking this option will display the screen of Figure 4, where we can set the place where the application will be published.

 

cdscwvsfig04.jpg 

Figure 4. Choosing where to publish the application.

 

Clicking Next, we will set the mode in which the application will be made available (Figure 5).

 

cdscwvsfig05.jpg 

Figure 5. Setting the application’s distribution mode.

 

We can set the application to be distributed in two ways:

·         Available online or offline: In this case, the application will actually be installed in the user’s computer, through a Setup;

·         Only available online: The application will run only if the site is online, since it will not be actually installed in the user’s computer.

 

Finally, clicking Next ands Finish, the application will be published.

 

Running the application through the browser

After finishing the publication, in Visual Studio open the browser at the place where the application was published, in our case: http://MachineName/MyFirstSmartClient/publish.htm. The page in Figure 6 will be displayed.

 

cdscwvsfig06.jpg 

Figure 6. Running the application in the browser.

 

Notice that we have a Run button, which will run the application or the installation in the customer’s machine, in accordance to the supplied configurations to the SmartClient. To run the application, we must validate its installation, since it is an executable program which is coming through the browser. The screen in Figure 7 will be shown.

 

cdscwvsfig07.jpg 

Figure 7. Validating the application’s installation.

 

Since we choose to publish the application by installing it in the user’s computer, a shortcut was added to the start menu and the application may be called from there, still being updated, if necessary. And to remove it, it is enough to open the Control Panel, and uninstall it, like any application.

 

In case the application has been set to run only online, Figure 8 shows what the execution will be like in this case. Keeping in mind that in this mode, nothing is installed in the user’s machine. The publish.htm file that displays the SmartClient page in the browser can be modified and personalized according to your company’s standards.

 

cdscwvsfig08.jpg 

Figure 8. Running the application without installing in the client.

 

How to update the application?

This is the simplest part. All you do is make the necessary modifications in your application and repeat the publication process, which was described previously. As soon as the user runs the application, either straight in the browser or by the shortcut, everything will be automatically updated.

 

Conclusion

We have demonstrated here how simple and fast it is to distribute your Windows Forms applications through the browser. Something that confers it great velocity and easiness to maintain and update. This is a very interesting way to benefit from your intranet/extranet features, maintaining the richness of your Windows applications.

 

We could go on talking about SmartClients for several pages, but our purpose is to show how simple it is to transform Windows Forms applications into SmartClients, using the ClickOnce technology present in Visual Studio 2005. I hope to see many SmartClients in action very soon. Cheers and see you next time!

 

Links

msdn.microsoft.com/netframework/windowsforms/learning/features/clickonce/

Official site for the SmartClient (ClickOnce) feature.

 



colunista nao disponivel

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login