Click here to Skip to main content
6,635,885 members and growing! (20,623 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, .NET, Win2K, WinXP, ASP.NET, WebForms, VS2005, Dev
Posted:16 Jul 2007
Views:11,185
Bookmarked:18 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 2.14 Rating: 2.38 out of 5
5 votes, 62.5%
1

2

3
1 vote, 12.5%
4
2 votes, 25.0%
5

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


Member
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
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Generali can't either Pinmemberirfan aza20:20 9 Nov '09  
GeneralCode Pinmembervunhuthang21: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-2009
Web17 | Advertise on the Code Project