![]() |
Languages »
VB.NET »
General
Advanced
Download Manager for update ApplicationBy alex_pa_72This article descrive how to build a component for manage download files of a program |
VB 8.0, .NET, Win2K, WinXP, ASP.NET, WebForms, VS2005, Dev
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
As .NET Developer for implement a project that will check on some web server if there are update i use microsoft "ClickOnce".
But because this application will be run on Windows locked i prefered to use the code to make the goal.
The principal component of this project are:
The file Xml is structured on this way:
<?xml version="1.0" encoding="utf-8" ?>
<Updates>
<update id="1" dtUpdate="2007_06_01" version="1_0_0_1" RestartFastBet="False">
<details>
<file remote="http://youWebServer/fastbet_Download/1_0_0_1/fastbet.exe" locale="fastbet.exe" MustStart="False"></file>
<config key="Last_Update" section="Update" value="2007_06_01"></config>
</details>
</update>
<update id="2" dtUpdate="2007_07_02" version="1_0_0_1" RestartFastBet="False">
<details>
<config key="Last_Update" section="Update" value="2007_07_02"></config>
</details>
</update>
</Updates>
Every TAG update is a new version of program, the date of this version is attribute dtUpdate inside update node, so if version of program (that i match with key getSetting("FastBet", "Update", "LastUpdate") is old, the first thig that i do is to download file and metadata.
The file of new version i found with attributes inside <file> node.
The attribute remote is the URI where the file must be downloaded, and locale is the path where the file must will copied on local machine.
And Metadata is represented with node <config>.
The metadata section have the same attribute use to save key on registry:
savesetting("Fastbet", "[section]","[key]", "[value]").
Below we can see how this works!
In the component update part I use the class Update.
On this class there is a method that will get file xml and it will be loaded in XMLDoc property:
Public Sub CheckForUpdate(ByVal sUrl As String)
Dim Request As HttpWebRequest = CType(WebRequest.Create(sUrl), HttpWebRequest)
Dim response As HttpWebResponse = CType(Request.GetResponse, HttpWebResponse)
Dim responseStream As StreamReader = New StreamReader
response.GetResponseStream()
Dim output As String = responseStream.ReadToEnd()
responseStream.Close()
response.Close()
xMLdOC.LoadXml(output)
End Sub
Function Main()
Try
Dim bytesProcessed As Integer = 0
Dim remoteStream As Stream = Nothing
Dim localeStream As Stream = Nothing
Dim response As HttpWebResponse = Nothing
Dim request As HttpWebRequest = CType(WebRequest.Create(remoteFile), HttpWebRequest)
response = request.GetResponse
If Not response Is Nothing Then
remoteStream = response.GetResponseStream
localeStream = File.Create(LocaleFile)
Dim buffer(1024) As Byte
Dim Bytesread As Integer
Do
Bytesread = remoteStream.Read(buffer, 0, buffer.Length)
localeStream.Write(buffer, 0, Bytesread)
bytesProcessed += Bytesread
If Bytesread = 0 Then Exit Do
Loop
If Not response Is Nothing Then response.Close()
If Not remoteStream Is Nothing Then remoteStream.Close()
If Not localeStream Is Nothing Then localeStream.Close()
End If
Return bytesProcessed
End Function
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 16 Jul 2007 Editor: |
Copyright 2007 by alex_pa_72 Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |