Program Version Number

B

Bill Cart

We are using c# windows forms and just trying to get started with .net. I
want to do something that should be easy but I can't find any way to make it
work. We are using Click Once to publish to a network drive and I need to be
able to check if a program is the current version. Because the users can
choose to not download the latest version this may be a problem. I just want
to show what version they are running.

I found some code that gave me:

private void FrmMain_Load(object sender, EventArgs e)
{
FileVersionInfo fvi =
FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
string version = fvi.FileVersion.ToString();
MessageBox.Show(version);
}

I am not sure if this will give me what I need. And it also gets an error I
don't understand. Why would gettting the version number be a security
exception?

System.Security.SecurityException was unhandled
Message="Request failed."
Source="AfterSchool1"
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


| We are using c# windows forms and just trying to get started with .net. I
| want to do something that should be easy but I can't find any way to make
it
| work. We are using Click Once to publish to a network drive and I need to
be
| able to check if a program is the current version. Because the users can
| choose to not download the latest version this may be a problem. I just
want
| to show what version they are running.

Try:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();--Ignacio Machinmachin AT laceupsolutions com
 
G

Ginger Estherskip

For ClickOnce, that won't give the current version number... instead (from a
post by Andrej Tozon):

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
Version version =
System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
string versionString = version.ToString();
}
 
B

Bill Cart

I tried the System.Deployment method
System.Deployment.Application.ApplicationDeployment ad1 =
System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
System.Windows.Forms.MessageBox.Show(ad1.CurrentVersion.ToString());

but when I test it I get the following error:

System.Deployment.Application.InvalidDeploymentException was unhandled
Message="Application is not installed."
Source="System.Deployment"

I just found out the it only does this in the debuger so I guess that makes
sense, it really is not deployed yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top