Solved

Setting Version and Date Information - Syntax help needed.

Posted on 2006-07-21
13
249 Views
Last Modified: 2012-06-27
Friends,

I have the following code:

Imports System.IO.FileInfo

Public Class VersionInformation
    Inherits System.Windows.Forms.Form


    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub VersionInformation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim myAssemblyPath As String
        Dim a As Reflection.Assembly = _
        System.Reflection.Assembly.GetExecutingAssembly()
        myAssemblyPath = _
        a.Location.Substring(0, InStrRev(a.Location, "\"))

        Dim fileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location ) <--------- I'm getting an error, Assembly - Expression expected

        lblVersion.Text= System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location) <--------- I'm getting an error, Assembly - Expression expected
        lblDate.text = <---------- What does I need to put here to get the Date Modified?
    End Sub
End Class

This code was given to me by another poster, but I'm not sure how to tie it all together, and I'm in a hurry for a response.

Thanks in advance!
Best Regards,
Eric
0
Comment
Question by:indy500fan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155735
Assembly.GetExecutingAssembly().Location can return different types of values depending on whether the assembly is in the GAC or not, etc.

What is the actual value returned by "Assembly.GetExecutingAssembly().Location" when the error occurs?
0
 

Author Comment

by:indy500fan
ID: 17155748
??? I can't tell you that, because this won't even compile as it is.  By the way, what is GAC?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17155758

GAC is Global Assembly Cache. If more than one application on your machine is using the same component, you can palce that component to GAC
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 17155771

one of the benefits of doing that is that if you make a change to that component, you won't need to go into every application that uses the component and replace the local copy with an updated version. Using GAC saves you from "DLL Hell" we had in VB6
0
 

Author Comment

by:indy500fan
ID: 17155794
From what is described here: I don't think I have multiple apps using this component.  This all seems very complicated (compounded by my stupidity)

This form is a part of a simple exe.  Is there an easier way to find out the file version and date of the exe so that I can display them in an about form?
0
 
LVL 24

Accepted Solution

by:
Justin_W earned 500 total points
ID: 17155810
Oh, a compilation error, not a runtime error.

Use this:

Imports System.IO
Imports System
Imports System.Reflection

Public Class VersionInformation
    Inherits System.Windows.Forms.Form

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub VersionInformation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim myAssemblyPath As String
        Dim a As Reflection.Assembly = _
        System.Reflection.Assembly.GetExecutingAssembly()
        myAssemblyPath = _
        a.Location.Substring(0, InStrRev(a.Location, "\"))

        Dim fi As System.IO.FileInfo = New FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)

        lblVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)
        lblDate.text = fi.LastWriteTime.ToString()
    End Sub
End Class
0
 

Author Comment

by:indy500fan
ID: 17155848
Justin,

Yeah, sorry I didn't specify the type of error earlier.

It's now giving me another compliation error:

Value of type 'System.Diagnostics.FileVersionInfo' cannot be converted to 'String'.
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155905
lblVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString()
0
 

Author Comment

by:indy500fan
ID: 17155934
Justin,

You have gotten me closer than anyone else today, but this code gives me The exact path to the exe, not the file version number?

Am I driving you nuts yet?

Thanks,
Eric
0
 

Author Comment

by:indy500fan
ID: 17155964
Ah, I just realized, it actually gave me all the information. I didn't have a lbl box that was "tall enough"

I'm going to ask in another question a way to limit it to just the version number.

Thanks for your help!
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155971
Imports System.IO
Imports System
Imports System.Reflection

Public Class VersionInformation
    Inherits System.Windows.Forms.Form

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub VersionInformation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim myAssemblyPath As String
        Dim a As Reflection.Assembly = _
        System.Reflection.Assembly.GetExecutingAssembly()
        myAssemblyPath = _
        a.Location.Substring(0, InStrRev(a.Location, "\"))

        Dim fi As System.IO.FileInfo = New FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)

        Dim loc As String = System.Reflection.Assembly.GetExecutingAssembly().Location
        lblVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(loc).FileVersion
        lblDate.text = fi.LastWriteTime.ToString()
    End Sub
End Class
0
 

Author Comment

by:indy500fan
ID: 17155990
Dude,

You rock!

Thank you VERY MUCH!!!

Eric
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155994
You're welcome!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question