vb.net读写在线存储的XML文件 [英] vb.net reading and writing an XML file stored online

查看:55
本文介绍了vb.net读写在线存储的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我需要这个项目的帮助.
您可能需要阅读两次...

我想要做的是在测试Windows SBS Server上使用vb.net应用程序来读取托管在我的企业网站上的测试文件夹中的xml文件.

xml文件可能包含一些我不希望我的客户用户读取或复制的数据.
我知道我可以使用vb.net从Web下载xml文件,然后设置变量和类似的内容.

我想在两件事上有所帮助;
Vb.net代码无需下载即可在线读取xml文件.
和xml加密,用于测试,我现在不需要.

这是我用来下载xml文件并阅读它的代码,只是一个简单的更新程序.

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"
 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


是的,我是在午休时间做的
代码将执行的操作是下载Web的Update.xml文件.
阅读下载文件位置"Update_Location1",然后将其下载(我将对其进行修改,因为我可能会使用它是一种不好的方法)


还有Update.xml文件


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"?>
<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>




这是读写xml文件的正确方法吗?
我可以读取/写入站点上的XML文件,还是需要下载读取/写入然后通过FTP上传?

一切正常后,我将从测试应用程序中上传源代码.

感谢您阅读所有内容.




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.

推荐答案

关键是要了解如何在类结构和它们之间来回反序列化xml对象. d拥有对一切的完全控制权...以及更新现在存储xml并仅存储class的类对象的能力.保存并将其写回该对象...

此处"进入主题:: :: http://support.microsoft.com/kb/316730 br mode = "hold"/>如果您只想操作XML,请查看XElement和XDocument对象...真是太棒了.
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.


这篇关于vb.net读写在线存储的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆