- Company: Company goes here
- Title: Title goes here
- Description: Description goes here
- CLS Compliant: True
- Product: Product goes here
- Guid: BFC0B506-B50B-457F-BC84-A104B8B22035
- Trademark: Trademark goes here
- Copyright: Copyright goes here
- Website version: 1.0.2662.16081
ASP.NET: Display Version Information
From Wiki
Summary: An example of how we can use an AssemblyInfo file to show version information on our page
There may be cases when we would like to display some information about our application (such as it's name, description or build number). Fortunately, we can enter this information ourselves by creating a file named AssemblyInfo.vb and placing it in the App_Code folder. Here's an example of what to include in this file:
- Imports System
- Imports System.Reflection
- Imports System.Runtime.InteropServices
- ' General Information about an assembly is controlled through the following
- ' set of attributes. Change these attribute values to modify the information
- ' associated with an assembly.
- ' Review the values of the assembly attributes
- <Assembly: AssemblyTitle("Title goes here")>
- <Assembly: AssemblyDescription("Description goes here")>
- <Assembly: AssemblyCompany("Company goes here")>
- <Assembly: AssemblyProduct("Product goes here")>
- <Assembly: AssemblyCopyright("Copyright goes here")>
- <Assembly: AssemblyTrademark("Trademark goes here")>
- <Assembly: CLSCompliant(True)>
- 'The following GUID is for the ID of the typelib if this project is exposed to COM
- <Assembly: Guid("BFC0B506-B50B-457F-BC84-A104B8B22035")>
- ' Version information for an assembly consists of the following four values:
- '
- ' Major Version
- ' Minor Version
- ' Build Number
- ' Revision
- '
- ' You can specify all the values or you can default the Build and Revision Numbers
- ' by using the '*' as shown below:
- <Assembly: AssemblyVersion("1.0.*")>
You can see that we have sections where we can enter attributes such as the Title and Description of the site. Also, at the bottom of the file, we can set the version information of the site. You can do this by including the full major, minor, build and revision numbers yourself e.g. (1.0.1.1) or you can just set the major and minor numbers and use a wildcard for the build and revision so that ASP.NET generates them automatically (which is what I have done in the example above).
To display this information, I've created a simple page with a label to display the data:
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="VersionInformation.aspx.vb" Inherits="VersionInformation" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
- </div>
- </form>
- </body>
- </html>
We then need to use the System.Reflection class to iterate through all of this information and display it on the page:
- Imports System.Reflection
- Imports System.Text
- Partial Class VersionInformation
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- 'Declarations
- Dim assembly As System.Reflection.Assembly
- Dim sb As New StringBuilder
- ' Load the assembly info
- assembly = System.Reflection.Assembly.Load("App_Code")
- ' Iterate through all the attributes for the assembly.
- For Each attr As Attribute In Attribute.GetCustomAttributes(assembly)
- ' Append each value to the StringBuilder
- Select Case attr.GetType.ToString
- Case "System.Reflection.AssemblyTitleAttribute"
- sb.Append("Title: " & CType(attr, AssemblyTitleAttribute).Title & "<br>")
- Case "System.Reflection.AssemblyDescriptionAttribute"
- sb.Append("Description: " & CType(attr, AssemblyDescriptionAttribute).Description & "<br>")
- Case "System.Reflection.AssemblyCompanyAttribute"
- sb.Append("Company: " & CType(attr, AssemblyCompanyAttribute).Company & "<br>")
- Case "System.Reflection.AssemblyProductAttribute"
- sb.Append("Product: " & CType(attr, AssemblyProductAttribute).Product & "<br>")
- Case "System.Reflection.AssemblyCopyrightAttribute"
- sb.Append("Copyright: " & CType(attr, AssemblyCopyrightAttribute).Copyright & "<br>")
- Case "System.Reflection.AssemblyTrademarkAttribute"
- sb.Append("Trademark: " & CType(attr, AssemblyTrademarkAttribute).Trademark & "<br>")
- Case "System.CLSCompliantAttribute"
- sb.Append("CLS Compliant: " & CType(attr, CLSCompliantAttribute).IsCompliant & "<br>")
- Case "System.Runtime.InteropServices.GuidAttribute"
- sb.Append("Guid: " & CType(attr, System.Runtime.InteropServices.GuidAttribute).Value & "<br>")
- End Select
- Next
- ' Add the version info
- sb.Append("Website version: " & assembly.GetName().Version.ToString())
- ' Write out the details
- Label1.Text = sb.ToString
- End Sub
- End Class
When we run this page, we will see an output similar to this:
This Hack is part of the ASP.NET Hacks collection


