2011-04-20 6 views
0

Google에서봤을 때 "예"라고 대답하기 전에 질문을하기 전에 페이지 뒤 페이지를 읽었습니다. 사이트 후 사이트 및 필요한 정보를 얻을 수 없습니다.XML을 사용하여 응용 프로그램 업데이트 검사기

내 응용 프로그램에 대해 매우 간단한 업데이트 검사기를 만들려고합니다. 하나는 온라인 XML 파일을 구문 분석하고 특정 위치에 데이터를 표시합니다. 또한 다운로드 위치에 대한 링크를 파싱 할 수있을뿐만 아니라 (내 호스팅 계획이 3MB가 넘는 ftp 파일을 허용하지 않기 때문에 ftp 또는 기타가 아닌 파일 호스트와 같은 것임)

어쨌든 여기에 무엇입니까? 나는 지금까지 가지고 :

XML 코드 :

<code> 
    <Info> 
     <Version>2.8.0.0</Version> 

     <Link>www.filehost.com</Link> 

     <Description>Added New Features To GUI</Description> 

    </Info> 
</code> 

여기 응용 프로그램 코드, 그리고 내가 그것을 보여주고 싶은 무엇을.

using System; 
using System.Windows.Forms; 
using System.Xml; 

namespace SAM 
{ 
    public partial class UpdateCheck : DevExpress.XtraEditors.XtraForm 
    { 
     public UpdateCheck() 
     { 
      InitializeComponent(); 
      lblCurrentVersion.Text = "Current Version: " + Application.ProductVersion; 
     } 

     private void MainForm_Shown(object sender, EventArgs e) 
     { 
      BringToFront(); 
     } 


     private void BtnChkUpdate_Click(object sender, EventArgs e) 
     { 
      XmlDocument doc = new XmlDocument(); 
      doc.Load("http://www.crimson-downloads.com/SAM/UpdateCheck.xml"); 

     } 
    } 
} 

나는이 방법으로 XML을 구문 분석 할 응용 프로그램을 찾고 있습니다.

<Version>2.8.0.0</Version> Will change the text for "lblUpdateVersion" like how I got the current version label set in the InitializeComponent(); 
<Description>Added New Features To GUI</Description> to be parsed out into the "textDescription" Which I can probably do myself. 
<Link>www.filehost.com</Link> Will parse into the button control so when pressed will open up the users default browser and follow the link. 
+0

사용중인 .NET 버전은 무엇입니까? –

+0

무엇이 당신의 질문입니까? –

답변

2

나는 내 자신의 응용 프로그램 에서이 정확한 일을했습니다.

먼저, 업데이터 정보를 보유하고있는 웹 호스트에 XML 파일을 저장합니다. 광산 http://getquitter.com/version.xml에 있으며 다음과 같이 구성되어있다 :

<versioninformation> 
    <latestversion>1.2.0.0</latestversion> 
    <latestversionurl>http://www.getquitter.com/quitter-1.2.0.zip</latestversionurl> 
    <filename>quitter-1.2.0.zip</filename> 
</versioninformation> 

둘째 호스트에서 해당 XML을 검색하는 방법을 쓰기 :

Public Function GetWebPage(ByVal URL As String) As String 
    Dim Request As System.Net.HttpWebRequest = CType(WebRequest.Create(New Uri(URL)), HttpWebRequest) 
    With Request 
     .Method = "GET" 
     .MaximumAutomaticRedirections = 4 
     .MaximumResponseHeadersLength = 4 
     .ContentLength = 0 
    End With 

    Dim ReadStream As StreamReader = Nothing 
    Dim Response As HttpWebResponse = Nothing 
    Dim ResponseText As String = String.Empty 

    Try 
     Response = CType(Request.GetResponse, HttpWebResponse) 
     Dim ReceiveStream As Stream = Response.GetResponseStream 
     ReadStream = New StreamReader(ReceiveStream, System.Text.Encoding.UTF8) 
     ResponseText = ReadStream.ReadToEnd 
     Response.Close() 
     ReadStream.Close() 

    Catch ex As Exception 
     ResponseText = String.Empty 
    End Try 

    Return ResponseText 
End Function 

다음을, XML을 얻기 위해이 메소드를 호출하고,로로드 XML 문서.

Dim VersionInfo As New System.Xml.XmlDocument 
VersionInfo.LoadXml(GetWebPage("http://www.getquitter.com/version.xml")) 

version.xml을로드하면 새 버전을 가져올 지 여부를 결정하는 데 필요한 개별 데이터를 구문 분석 할 수 있습니다.

Dim LatestVersion As New Version(QuitterInfoXML.SelectSingleNode("//latestversion").InnerText) 
Dim CurrentVersion As Version = My.Application.Info.Version 
If LatestVersion > CurrentVersion Then 
    ''download the new version using the Url in the xml 
End If 

이것이 내 응용 프로그램의 기능입니다. 원하는 경우 소스 코드를 다운로드하여 모델로 사용할 수 있습니다 (오픈 소스 응용 프로그램). http://quitter.codeplex.com입니다. 희망이 도움이!

+0

답장을 보내 주시면 죄송합니다. 그것은 내가 원했던 방식대로 작동했습니다. 귀하의 XML 형식을 사용했지만, 변경 로그를 추가 할 수 있도록 작은 변경을했습니다. 또한 약 페이지 및 사이트에 대한 링크에 나를 추가했습니다. – McWxXx

+0

다행 당신을 위해 일하고, 당신의 "정보"페이지에 언급에 대해 대단히 감사합니다! – DWRoelands

1
using System; 
using System.Windows.Forms; 
using System.Xml; 
using System.Net; 
using System.IO; 
using System.Diagnostics; 

namespace SAM 
{ 

    public partial class UpdateCheck : DevExpress.XtraEditors.XtraForm 
    { 
     public UpdateCheck() 
     { 
      InitializeComponent(); 
      lblCurrentVersion.Text = "Current Version: " + Application.ProductVersion; 
     } 

     private void MainForm_Shown(object sender, EventArgs e) 
     { 
      BringToFront(); 
     } 

     public static string GetWebPage(string URL) 
     { 
      System.Net.HttpWebRequest Request = (HttpWebRequest)(WebRequest.Create(new Uri(URL))); 
      Request.Method = "GET"; 
      Request.MaximumAutomaticRedirections = 4; 
      Request.MaximumResponseHeadersLength = 4; 
      Request.ContentLength = 0; 

      StreamReader ReadStream = null; 
      HttpWebResponse Response = null; 
      string ResponseText = string.Empty; 

      try 
      { 
       Response = (HttpWebResponse)(Request.GetResponse()); 
       Stream ReceiveStream = Response.GetResponseStream(); 
       ReadStream = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8); 
       ResponseText = ReadStream.ReadToEnd(); 
       Response.Close(); 
       ReadStream.Close(); 

      } 
      catch (Exception ex) 
      { 
       ResponseText = string.Empty; 
      } 

      return ResponseText; 
     } 

     private void BtnChkUpdate_Click(object sender, EventArgs e) 
     { 
      System.Xml.XmlDocument VersionInfo = new System.Xml.XmlDocument(); 
      VersionInfo.LoadXml(GetWebPage("http://www.crimson-downloads.com/SAM/UpdateCheck.xml")); 

      lblUpdateVersion.Text = "Latest Version: " + (VersionInfo.SelectSingleNode("//latestversion").InnerText); 

      textDescription.Text = VersionInfo.SelectSingleNode("//description").InnerText; 

     } 

     private void simpleButton2_Click(object sender, EventArgs e) 
     { 
      Process process = new Process(); 
      // Configure the process using the StartInfo properties. 
      process.StartInfo.FileName = "http://www.crimson-downloads.com/SAM/Refresh.htm"; 
      process.StartInfo.Arguments = "-n"; 
      process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; 
      process.Start(); 
     } 
    } 
} 

간단하고 간단합니다. 고마워, XML을 사용하는 다른 문제가 있었지만, 나에게 준 도움으로 지식을 적용 할 수 있었고 효과가있었습니다.

관련 문제