File Version

  • Thread starter Thread starter Dennis C. Drumm
  • Start date Start date
D

Dennis C. Drumm

I am trying to find a way to compare the version of the currently executing
assembly to the version of my latest upload so I can notify the user when a
newer version is available.

Is it possible to get the version information programmatically for an exe
file in some folder on my web site or alternatively to retrieve the version
information from information appearing on a web page on my web site?

Thanks,

Dennis
 
Hi Dennis,
You can retrieve the Version object which contains the Major, Minor, Build,
and Revision properties of the assembly version.

Cheers,
Steve Goodyear

System.Version version =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
MessageBox.Show(version.ToString());
 
Steve:

Thanks, but I knew that! What I had asked is how to retrieve the file
version of an exe from my server (the bundled install program) or how to
read some text from a page on my web site that contains version information
for the latest build.

Of course, I suppose I could embed the file version in a simple ascii text
file on my server and read that, but then that is one more thing that must
be remembered every time an upload is done.

Thanks,

Dennis
 
Hi Dennis,

As for the
===================
how to read some text from a page on my web site that contains version
information for the latest build.
===================

do you mean that you'd like to provide a dynamic web page on your
webserver(IIS) which will return the components/application's update list
info? If so, I think it's a good idea and you can consider define your
update info as xml data so that the web page can return xml document to
client (contentType="text/xml").

Then, in the clientside, we can use the HttpWebRequest class (under
System.Net namespace) to retrieve the xml data from that web page). How do
you think of this? If you feel it's a possbile approach, I can paste some
sample code on using HttpWebRequest component to get response text from a
remote page.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steven:

My preference would be to get the version information for the setup.exe file
I upload to my web site for users to download. The setup.exe file is a
compressed setup file that contains all the dll and exe files
(assemblies)necessary for the program.

If that is not possible, then another method would need to be employed, such
as you mention. I have not worked with dynamic web pages, so I really can't
say if that will do or not. I will do some reading on that subject.

How about just reading a user variable property, a custom metadata element)
that I set for the downloads.htm web page of my site? Can I read that data
remotely? If so, it would be easy to set a value named Version and provide
its value every time I upload a new version.

Again, I would prefer to get that information directly from the uploaded
file it at all possible.

Thanks,

Dennis
 
Hi Dennis,

Thanks for your reply. Actually the reason why I suggest use a page or
document to publish your application's update list is because the client
users are remote to the server you upload your setup package. So even if we
can easily get the version info from the setup package, we need to download
the setup package first( this will cause addiontal network transport. Also,
even we get the setup package download, we can't directly get info from the
package, we need to programmatically uncompressed the package and check
version from the file(such as asssemblies) in it. So I think using a text
format on the server and let the client applicaiton to request that text
file to get the latest update list info is the reasonable approach. In
.net, we can finish this through the following steps:

1. Put a xml static file on the server which contains the update list info
of your application/components

2. In client application, use the .net's HttpWebRequest component to get
the xml document on the remote server and load into a XmlDocument class

3. Use XPath to query the version information in the xmldocument and
determine whether to download update files or not.

How do you think of this? If you feel necessary I can post some sample code
snippet on this.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steven:

Yes, please show me some code snippets to extract version information from
an xml file.

Thanks,

Dennis
 
Hi Dennis,

The reason I suggest XML file is because XML file provide well-formed
structure for storing and representing data and the classes under
System.Xml namespace has provide sufficient interfaces for us to process
XML data. For example, we have the following format of version info:

=================
<?xml version="1.0" encoding="utf-8" ?>
<versionInfo>
<latest version="1.0.4.438">
<assemblies>
<assembly fullName="System.Data, Version=1.0.2411.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
<package location="http://servername/downloaddir/myapp104438.zip" />
</assemblies>
</latest>
</versionInfo>
====================

the file is located at
http://sha-schost-01/StevenRoot/SearchFriendApp/updateinfo/version.xml

Then we can use the following


===================
string url=
"http://sha-schost-01/StevenRoot/SearchFriendApp/updateinfo/version.xml";
XmlDocument doc = null;

try
{

doc = new XmlDocument();
doc.Load(url);

XmlElement latestVersion = doc.SelectSingleNode("//latest") as XmlElement;
//display the version attribute's value
MessageBox.Show( latestVersion.Attributes["version"].Value
);

}
catch(System.Net.WebException webex)
{
txtResponse.Text += "\r\n" + webex.ToString();
}
catch(Exception ex)
{
txtResponse.Text += "\r\n" + ex.ToString();
}
finally
{
sr.Close();
}
=====================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steven:

That is a geat help!

But, I was expecting something about the use of HttpWebRequest as mentioned
in your last two posts.

Also you have a line sr.Close(). What is sr?

Thanks,

Dennis
 
Thanks for your response Dennis,

You're a sharp guy :-). Actually, I did use the HttpWebRequest in the demo
code at first, however since using XmlDocument.Load method is much more
convenient and clear, so I changed to that(the sr is an instance of
StreamReader ). Well, I've pasted the complete code of using
HttpWebRequest to retrieve the xml stream from server, also using
httpWebRequest is not restricted to Xml document, we can retrieve any
static content/ dynamic document from server by it.

=============================
private void btnReadUpdate_Click(object sender, System.EventArgs e)
{

HttpWebRequest webreq = null;
HttpWebResponse webrep = null;
StreamReader sr = null;
string url= "http://servername/dirname/version.xml";
XmlDocument doc = null;


try
{
webreq = WebRequest.Create(url) as HttpWebRequest;
webrep = webreq.GetResponse() as HttpWebResponse;
sr = new
StreamReader(webrep.GetResponseStream(),System.Text.Encoding.UTF8);


doc = new XmlDocument();
doc.Load(sr);

XmlElement latestVersion = doc.SelectSingleNode("//latest") as
XmlElement;


txtResponse.Text += "\r\n" + latestVersion.Attributes["version"].Value;
}
catch(System.Net.WebException webex)
{
txtResponse.Text += "\r\n" + webex.ToString();
}
catch(Exception ex)
{
txtResponse.Text += "\r\n" + ex.ToString();
}
finally
{
sr.Close();
}
}
========================

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steven:]

Thank you very much, between what I was able to get from some google
searches and the stuff you have provided, it has given me a jump start into
xml, which is a new thing for me!!

Dennis
 
Back
Top