To create a small program similar to the clickonce function, store program information in XML, and then determine whether the program version on the server is updated. If so, download the new version to the specified path and then call it. another problem is that I don't know how to close the update program.
The clickonce function of vs2005 is indeed good and easy to use.
Updatever. xml
<Updateinfo>
<Preversion> 1.0.0.1 </preversion>
<Updatepath> http: // localhost/testc1/apps/</updatepath>
<Currentpath> C:/backup/my projects/updatever/bin/debug/update/</currentpath>
<Exefile> testc1.exe </exefile>
<Files>
<File> c1.common. dll </File>
<File> c1.win. c1input. dll </File>
<File> c1.win. c1list. dll </File>
<File> c1.win. c1truedbgrid. dll </File>
<File> dbconfig. xml </File>
<File> devcomponents. dotnetbar. dll </File>
</Files>
</Updateinfo>
Updatever. CS
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. reflection;
Using system. net;
Using system. xml;
Using system. IO;
Using system. diagnostics;
Namespace updatever
{
Class updaetver
{
Public String prever;
Public String curver;
Public String updatepath;
Public String curpath;
Public String exefilename;
Public String [] files;
Public void loadxml ()
{
Xmldocument Doc = new xmldocument ();
Doc. Load ("updatever. xml ");
Xmlnode node = Doc. childnodes [1];
Prever = node. childnodes [0]. innertext;
Updatepath = node. childnodes [1]. innertext;
Curpath = node. childnodes [2]. innertext;
Exefilename = node. childnodes [3]. innertext;
Int filecount = node. childnodes [4]. childnodes. count;
Files = new string [filecount];
For (INT I = 0; I <filecount; I ++)
{
Files [I] = node. childnodes [4]. childnodes [I]. innertext;
}
}
Public void savexml ()
{
Xmldocument Doc = new xmldocument ();
Doc. Load ("updatever. xml ");
Xmlnode node = Doc. childnodes [1];
Node. childnodes [0]. innertext = curver;
Doc. Save ("updatever. xml ");
}
Public bool checkversion ()
{
Loadxml ();
Assembly A = assembly. loadfrom (updatepath + exefilename );
Version newver = A. getname (). version;
Curver = newver. tostring ();
Version oldver = new version (PreveR );
Int check = newver. compareto (oldver );
If (check> 0)
Return true;
Else
Return false;
}
Public void updateversion ()
{
If (! Directory. exists (curpath ))
{
Directory. createdirectory (curpath );
}
WebClient = new WebClient ();
String exefilename = exefilename;
WebClient. downloadfile (updatepath + exefilename, curpath + exefilename );
For (INT I = 0; I <files. length; I ++)
{
String filename = files [I];
Console. writeline (filename );
WebClient. downloadfile (updatepath + filename, curpath + filename );
}
}
Public void runapplication ()
{
If (file. exists (curpath + exefilename ))
{
Processstartinfo info = new processstartinfo (curpath + exefilename );
Info. workingdirectory = curpath;
Process. Start (Info );
}
}
Public void Update ()
{
Bool check = checkversion ();
If (check = true)
{
Updateversion ();
Savexml ();
}
Runapplication ();
}
}
}