. NET WinForm Software Automatic Update __.net

Source: Internet
Author: User

About the. NET Windows software Implementation of Automatic Updates, I wrote a demo today for your reference.

Let's look at the effect chart:

Mainly involves two aspects

1. Update the Software master project and DLL files

2. Upgrade the package itself update

1. A project usually includes the main project and the class Library project, the main project is the startup project, at the end of the. exe, the class library project is mainly a DLL, and the simple update is to update the local master project and the class Library project.

You can use the latest software on a remote server, and then every time you start the local software, check if there is an update, download the latest from the server. EXE files and DLL files,

To replace the local DLL files and EXE files

Implementation of the idea: the local and the server put an XML file, which records the software version number, release date, to update the DLL and some other information, if you find the local software version number and the server is not equal, or

When the class library project in the local software is published later than the service, it starts downloading files on the server and replaces the local files.

The XML format is as follows

<?xml version= "1.0" encoding= "Utf-8"?>
<AutoUpdater>
  <appname>winupdate</appname >
  <ReleaseURL>http://127.0.0.1/webdown/</ReleaseURL>
  <RELEASEDATE>2012/3/1 10:42:34</releasedate>
  <ReleaseVersion>1.0.1.99</ReleaseVersion>
  <MinVersion> 1.0.1.88</minversion>
  <UpdateDes>
    1,	Add print menu
    2, add	DLL
    3, add about module
  </ updatedes>
  <ApplicationStart>WinUpdate.exe</ApplicationStart>
  <shortcuticon>ico </ShortcutIcon>
  <Releases>
    <file name= "AboutForm.dll" date= "2012/2/21 10:07:31" size= "39" />
  </Releases>
</AutoUpdater>

      public static void DownloadFile (String localfolder, String Remotefolder, String fileName, ProgressBar bar,
            Label lblsize) {string url = remotefolder + '/' + fileName;
            String path = localfolder+ fileName;
            String dir = Path.getdirectoryname (Path); if (!

            Directory.Exists (dir)) directory.createdirectory (dir);
            WebRequest req = webrequest.create (URL); WebResponse res = req.
            GetResponse (); if (res.

            ContentLength = = 0) return; Long filelength = Res.
            ContentLength; String totalsize = Formatfilesizedescription (bar.
            Maximum); using (Stream SRM = Res.
                GetResponseStream ()) {var srmreader = new StreamReader (SRM);
                var bufferbyte = new Byte[filelength]; int allbyte = Bufferbyte.
                Length;
                int startbyte = 0; While (Filelength > 0) {int downbyte = SRM.
                    Read (Bufferbyte, Startbyte, allbyte);
                    if (Downbyte = = 0) {break;
                    }
                    ;
                    Startbyte + = Downbyte;
                    Allbyte-= Downbyte; int progress = bar.
                    Value + downbyte; progress = progress > bar. Maximum? Bar.
                    maximum:progress; Bar.

                    Value = progress; Lblsize.text = string.
       
                Format ("Completed {0}/{1}", Formatfilesizedescription (Progress), totalsize);
                var fs = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Write); Fs. Write (bufferbyte, 0, Bufferbyte.
                Length); Srm.
                Close ();
                Srmreader.close (); Fs.
            Close (); }
        }
    }



2. About the upgrade package itself update, using the following ideas, placed a TXT file on the server, which stored the version number of the upgrade package, each time the local software startup,

Read the version number of the TXT file on the server and the version information for the local upgrade package, and if it is different, download the upgrade package from the server.

About downloading this project is done using WebClient.

You can test yourself in the following ways

First, create a virtual directory under your IIS:http://127.0.0.1/webdown , which is used to place the files to be updated, as follows

1.releaselist.xml and 1.0.4.98 folders are primarily software updates

The Releaselist.xml stores the content that needs to be updated. The 1.0.4.98 folder holds the class libraries and files that need to be updated

2. The upgrade packages implemented by the Autoupdate.exe,updaterverson.txt two files are updated themselves.

AutoUpdate.exe is the upgrade pack, UpdaterVerson.txt is storing the upgrade package version number

Deploy the content below to IIS

This code is developed using VS2008,

Demo download

http://download.csdn.net/detail/zx13525079024/4167121

Related Article

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.