5,696,576 members and growing! (15,886 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Advanced

Download Manager for update Application

By alex_pa_72

This article descrive how to build a component for manage download files of a program
VB 8.0, VB, .NET, Windows, Win2K, WinXP, WebForms, ASP.NET, VS2005, Visual Studio, Dev

Posted: 16 Jul 2007
Updated: 16 Jul 2007
Views: 6,870
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 2.14 Rating: 2.38 out of 5
5 votes, 62.5%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 12.5%
4
2 votes, 25.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

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.

Background

The principal component of this project are:

  1. a XML file that reside on Web server
  2. The Component Update
  3. The client of Component update
  4. The principal program

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!

Using the code

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

alex_pa_72


I have played various roles in IT since around 1998 when I began writing microsoft Access forms. I then moved to mainly coding in Visual Basic around 1999. Since the release of .net I have been mainly working in .net focusing in vb.net and very massive use of SQL Server.
Now i working for italian bookmaker like Web Developer on distribuited applicaitons.
Occupation: Web Developer
Location: Italy Italy

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralCodemembervunhuthang21:35 5 Dec '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Jul 2007
Editor:
Copyright 2007 by alex_pa_72
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project