c# - How to get the product Version number which is stored in the Deployment Project? -


i have winforms application written in c#. there deployment project creates setup.exe , set version number.

how can fetch version number @ runtime can write log or display in box?

i had been using following code not work 64-bit installations.

registrykey key = registry.localmachine.opensubkey(         @"software\microsoft\windows\currentversion\uninstall"); string[] subkeynames = key.getsubkeynames();  foreach (string subkeyname in subkeynames) {     microsoft.win32.registrykey subkey2 = key.opensubkey(subkeyname);      if (valuenameexists(subkey2.getvaluenames(), "displayname")          && valuenameexists(subkey2.getvaluenames(), "displayversion"))     {         string name = subkey2.getvalue("displayname").tostring();         string version = subkey2.getvalue("displayversion").tostring();         if(name == "myappname") return version;     }     subkey2.close(); } key.close(); return "v?"; 

you can try :

string registry_key = @"software\microsoft\windows\currentversion\uninstall"; using (microsoft.win32.registrykey key = microsoft.win32.registry.localmachine.opensubkey(registry_key)) {     foreach (string subkey_name in key.getsubkeynames())     {         using (microsoft.win32.registrykey subkey = key.opensubkey(subkey_name))         {             if (!object.referenceequals(subkey.getvalue("displayname"), null))             {                 string[] str = subkey.getvaluenames();                 string softnames = convert.tostring(subkey.getvalue("displayname"));                 if (softnames == "myappname")                 {                     string vendor_publisher = convert.tostring(subkey.getvalue("publisher"));                     string version = convert.tostring(subkey.getvalue("displayversion"));                     string installdate = formatdatetime(subkey.getvalue("installdate"));                 }              }         }     } }    private static string formatdatetime(object objinstalldate) {     object finaldate = dbnull.value;     string strdate = convert.tostring(objinstalldate);     datetime dtm;     datetime.tryparseexact(strdate, new string[] { "yyyymmdd", "yyyy-mm-dd", "dd-mm-yyyy" },          system.globalization.cultureinfo.invariantculture,         system.globalization.datetimestyles.none, out dtm);     if (!string.isnullorempty(strdate))     {                         finaldate = dtm;     }     return finaldate.tostring(); } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -