Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

VB
' This code works, it is still in testing so use use it how ever you want.

#Region "Region_Updater1"
 ublic 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
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Table>
       <Update>
              <Update_id>1</Update_id>
              <Update_Version>1.0.23.1</Update_Version>
              <Update_Location1>http://localhost/sites/update/application/files/1.0.0.23/test.zip</Update_Location1>
			  <Update_LocalPath>\Update.xml</Update_LocalPath>
       </Update>
</Table>



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
Comments
Sergey Alexandrovich Kryukov 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900