Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML VB.NET
Hello,
I would like some help on this project that I am working on.
you may need to read this twice...
 
what I am trying to do is use vb.net application on my testing Windows SBS Server to read an xml file hosted on my business website in a testing folder.
 
The xml file may contain some data that I don’t want my clients users to read or copy.
I know I can just use a vb.net to download the xml file from the web then set the variables and things like that.
 
I would like some help on 2 things;
Vb.net code to read the xml file online without downloading it.
and xml encryption, for testing I don’t need this right now.
 
this is the code that I use to download the xml file and read It, just a simple updater.
 
' This code works, it is still in testing so use use it how ever you want.

#Region "Region_Updater1"
Public urlfile As String = "http://localhost/sites/update/application/Update.xml"
 
Public XLocalLocation As String = Application.StartupPath & "\Update.xml"
    
Public xmlsettingslocation As String = Application.StartupPath & "\Settings.xml"
    
Public varFileExist As Boolean = False
 
#If 1 Then
    ''' <summary>
    ''' Xml Updater Sub
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SubUpdate() ' Its a good idea to use a thread and a module or somthing
        varFileExist = False
        Dim url As New System.Uri(urlfile)
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)
        'req = System.Net.WebRequest.Create(url)
        Dim resp As System.Net.WebResponse = Nothing
        Try
            WriteLog("System: Update XML Path; " & urlfile, Color.RoyalBlue)
            resp = req.GetResponse()
            resp.Close()
            req = Nothing
            If System.IO.File.Exists(XLocalLocation) = True Then System.IO.File.Delete(XLocalLocation) ' If you do not delete the file you will get an error, this will be improved latter on
            My.Computer.Network.DownloadFile(urlfile, XLocalLocation)
            varFileExist = True
            WriteLog("System: Connected To Update Server", Color.Green)
        Catch ex As Exception
            req = Nothing
            varFileExist = False
            WriteLog("System: Could Not Connect To Update Server, Path May Not Exist, Error: " & ex.Message, Color.Red)
        End Try
        WriteLog("System: Proceed With Download = " & varFileExist, Color.Orange)
        If varFileExist = True Then
            ' ======READ Update.xml file to String=========
            Dim fs As FileStream = Nothing : fs = New FileStream(Settings.XLocalLocation, FileMode.Open, FileAccess.Read) ' Works
            Dim xmldoc As New XmlDataDocument() : xmldoc.Load(fs)
            Dim xmlnode As XmlNodeList = Nothing : xmlnode = xmldoc.GetElementsByTagName("Update")
            Dim XVersion As String = Nothing : XVersion = xmlnode(0).ChildNodes.Item(1).InnerText.Trim()
            Dim XLocation As String = Nothing : XLocation = xmlnode(0).ChildNodes.Item(2).InnerText.Trim()
            fs.Close() ' Kill the XML Process
            '==============================================
            If (LogSettings = 2) Or (LogSettings = 3) Then WriteLog("System: Update Version: " & XVersion, Color.RoyalBlue)
            If (LogSettings = 2) Or (LogSettings = 3) Then WriteLog("System: Current Version: " & Application.ProductVersion, Color.RoyalBlue)
            If (LogSettings = 2) Or (LogSettings = 3) Then WriteLog("System: Update Location: " & XLocation, Color.RoyalBlue)
            If (LogSettings = 2) Or (LogSettings = 3) Then WriteLog("System: Update Local Location: " & Application.StartupPath & XLocalLocation, Color.RoyalBlue)
            Try
                WriteLog("System: Searching For Updates", Color.Orange)
                Dim ServerVersion As String = XVersion
                Dim ClientVersion As String = Application.ProductVersion 'NOTE: i need to change this to the Application Build Version for simplicity
                If ServerVersion = ClientVersion Then
                    WriteLog("System: Server Version Is Equal Newer Local Version.", Color.Orange)
                    'If ServerVersion.Contains(ClientVersion) Then
                    WriteLog("System: You Have The Current Updated Version Of The Application.", Color.Green)
                ElseIf ServerVersion < ClientVersion Then
                    WriteLog("System: Server Version Is Not Newer Local Version.", Color.Orange)
                    WriteLog("System: You Application's Version Is Greater Then The One On The Server", Color.Green)
                    WriteLog("System: This Is Likely An Error Or Maybe You Are Some Sort Of Super Admin God Or Something.", Color.RoyalBlue)
                    WriteLog("System: This Error Is From One Of The file Version On The Application Being To High Or The Version On The Server Being To Low.", Color.RoyalBlue)
                    WriteLog("System: Obviously You Are Not Meant To See This Very Silly Error, Could You Please Email The Developer At: EMAIL@ADDRESS.net.au", Color.RoyalBlue)
                    'WriteLog("System: If you Are Reading This Then The Developer Would Like To See The Application Action Logs", Color.Green)
                ElseIf ServerVersion > ClientVersion Then
                    WriteLog("System: Server Version Is Newer Local Version.", Color.Orange)
                    Try
                        WriteLog("System: Downloading Newer Version.", Color.Orange)
                        Process.Start(XLocation)
                        'My.Computer.Network.DownloadFile(XLocation, Application.StartupPath & XLocation) 'NOTE: This download method downloads like a Trojan, need to have (Open, Save, Close) the best way to do that is with a Web Browser Control
                        WriteLog("System: Download Complete.", Color.Green)
                    Catch ex As Exception
                        WriteLog("System: Could Not Download Update, Error: " & ex.Message, Color.Red)
                    End Try
                End If
            Catch ex As Exception
                WriteLog("System: Could Not Complete Updates, Error: " & ex.Message, Color.Red)
            End Try
        End If '  If varFileExist = True
    End Sub
#End If
#End Region 'Region_Updater1
Yeah, I made this in my lunch break
What the code will do is download the Update.xml file of the web.
Read the download dile location "Update_Location1" then download it (i will mod this as it could me used is a bad way)
 

And the Update.xml file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
 

Is this the right way of reading and writing the xml file?
Can i read / write to XML files on my site, or do i need to download read / write then upload via FTP?
 
I will upload the sorce code from the testing application after i have everything working.
 
Thanks for reading all of that.
Posted 21-Mar-12 18:06pm
Comments
SAKryukov at 22-Mar-12 0:11am
   
What does it mean: Vb.net code to read the xml file online without downloading it? Do you simple mean "without creation of temporary file"? From FTP? This is simple. It all depends on service...
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The key is to understand how to (de)serialize an xml object back and forth between a class structure and they you'd have yourself complete control over everything...and the ability to update your class object that is now storing your xml and simply class.Save and it writes write back to the object...
 
here's a lead into the topic :: http://support.microsoft.com/kb/316730br mode="hold" />If you want to just manipulate your XML, then look into the XElement and XDocument objects...really cool stuff.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 693
1 George Jonsson 370
2 BillWoodruff 317
3 Sergey Alexandrovich Kryukov 259
4 Garth J Lancaster 240
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 5 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100