asp.net C # Get program file related information

Source: Internet
Author: User
The code is as follows Copy Code

Using System.Reflection;
Using System.Runtime.CompilerServices;

//
General information about an assembly is passed through the following
Property set control. Change these property values to modify the assembly
The associated information.
//
[Assembly:assemblytitle ("")]
[Assembly:assemblydescription ("")]
[Assembly:assemblyconfiguration ("")]
[Assembly:assemblycompany ("")]
[Assembly:assemblyproduct ("")]
[Assembly:assemblycopyright ("")]
[Assembly:assemblytrademark ("")]
[Assembly:assemblyculture ("")]

//
The version information for an assembly consists of the following 4 values:
//
Major version
Minor version
Build number
Revision number
//
You can specify all of these values, or you can use the default values for the revision number and build number, by using the
Use the ' * ' as shown below:

[Assembly:assemblyversion ("1.0.*")]

//
To sign an assembly, you must specify the key that you want to use. For more information about assembly signing, refer to the
Microsoft. NET Framework documentation.
//
Use the following properties to control the key used for signing.
//
Attention:
(*) If no key is specified, the assembly is not signed.
(*) KeyName refers to a computer that is already installed on the
The key in the cryptographic service provider (CSP). KeyFile refers to the inclusion
The file for the key.
(*) If both keyfile and KeyName values have been specified, the
The following processing occurs:
(1) If KeyName can be found in the CSP, the key is used.
(2) If the KeyName does not exist and the keyfile exists, the
The key in the KeyFile is installed in the CSP and uses the key.
(*) to create a keyfile, you can use the Sn.exe (strong name) utility.
When specifying KeyFile, the position of the keyfile should be relative to the
Project output directory, i.e.
%project directory%obj<configuration>. For example, if KeyFile is located in
The project directory should be AssemblyKeyFile
property is specified as [Assembly:assemblykeyfile (]. \.. \mykey.snk ")]
(*) delay signature is an advanced option-for more information about it, see the Microsoft. NET Framework
Document.
//
[Assembly:assemblydelaysign (False)]
[Assembly:assemblykeyfile ("")]
[Assembly:assemblykeyname ("")]

Forms1.frm file here is the core program

The code is as follows Copy Code

Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.IO;
Using System.Diagnostics;
Download by Http://www.111cn.net
Namespace MyFile
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private System.Windows.Forms.Button button1;
Private System.Windows.Forms.TextBox TextBox1;
Private System.Windows.Forms.GroupBox GroupBox1;
Private System.Windows.Forms.OpenFileDialog OpenFileDialog1;
Private System.Windows.Forms.Button button2;
Private System.Windows.Forms.Label Label1;
Private System.Windows.Forms.Label Label2;
Private System.Windows.Forms.Label label3;
Private System.Windows.Forms.Label label4;
Private System.Windows.Forms.Label Label5;
Private System.Windows.Forms.Label label6;
Private System.Windows.Forms.Button Button3;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;

Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();

//
TODO: Add any constructor code after the InitializeComponent call
//
}

<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}

Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.button1 = new System.Windows.Forms.Button ();
This.textbox1 = new System.Windows.Forms.TextBox ();
This.groupbox1 = new System.Windows.Forms.GroupBox ();
This.openfiledialog1 = new System.Windows.Forms.OpenFileDialog ();
This.button2 = new System.Windows.Forms.Button ();
This.label1 = new System.Windows.Forms.Label ();
This.label2 = new System.Windows.Forms.Label ();
This.label3 = new System.Windows.Forms.Label ();
This.label4 = new System.Windows.Forms.Label ();
This.label5 = new System.Windows.Forms.Label ();
This.label6 = new System.Windows.Forms.Label ();
This.button3 = new System.Windows.Forms.Button ();
This.groupBox1.SuspendLayout ();
This. SuspendLayout ();
//
Button1
//
This.button1.Location = new System.Drawing.Point (8, 192);
This.button1.Name = "Button1";
This.button1.Size = new System.Drawing.Size (112, 23);
This.button1.TabIndex = 1;
This.button1.Text = "Browse program file";
This.button1.Click + = new System.EventHandler (This.button1_click);
//
TextBox1
//
This.textBox1.BackColor = System.Drawing.SystemColors.Control;
This.textBox1.Location = new System.Drawing.Point (104, 8);
This.textBox1.Name = "TextBox1";
This.textBox1.ReadOnly = true;
This.textBox1.Size = new System.Drawing.Size (256, 21);
This.textBox1.TabIndex = 2;
This.textBox1.Text = "";
//
GroupBox1
//
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL5);
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL4);
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL3);
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL2);
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL1);
This.groupBox1.Location = new System.Drawing.Point (8, 40);
This.groupBox1.Name = "GroupBox1";
This.groupBox1.Size = new System.Drawing.Size (352, 144);
This.groupBox1.TabIndex = 3;
This.groupBox1.TabStop = false;
This.groupBox1.Text = "program file information";
//
OpenFileDialog1
//
This.openFileDialog1.Filter = "program file (*.exe) |*.exe| All Files (*.*) |*.* ";
//
Button2
//
This.button2.Location = new System.Drawing.Point (120, 192);
This.button2.Name = "Button2";
This.button2.Size = new System.Drawing.Size (112, 23);
This.button2.TabIndex = 11;
This.button2.Text = "Get program file Information";
This.button2.Click + = new System.EventHandler (This.button2_click);
//
Label1
//
This.label1.Location = new System.Drawing.Point (16, 24);
This.label1.Name = "Label1";
This.label1.Size = new System.Drawing.Size (320, 16);
This.label1.TabIndex = 0;
This.label1.Text = "Company Name:";
//
Label2
//
This.label2.Location = new System.Drawing.Point (16, 48);
This.label2.Name = "Label2";
This.label2.Size = new System.Drawing.Size (320, 16);
This.label2.TabIndex = 1;
This.label2.Text = "Product Name:";
//
Label3
//
This.label3.Location = new System.Drawing.Point (16, 72);
This.label3.Name = "Label3";
This.label3.Size = new System.Drawing.Size (320, 16);
This.label3.TabIndex = 2;
This.label3.Text = "Language sign:";
//
Label4
//
This.label4.Location = new System.Drawing.Point (16, 96);
This.label4.Name = "Label4";
This.label4.Size = new System.Drawing.Size (320, 16);
This.label4.TabIndex = 3;
This.label4.Text = "version number:";
//
Label5
//
This.label5.Location = new System.Drawing.Point (16, 120);
This.label5.Name = "Label5";
This.label5.Size = new System.Drawing.Size (320, 16);
This.label5.TabIndex = 4;
This.label5.Text = "Copyright notice:";
//
Label6
//
This.label6.Location = new System.Drawing.Point (8, 16);
This.label6.Name = "Label6";
This.label6.Size = new System.Drawing.Size (96, 16);
This.label6.TabIndex = 12;
This.label6.Text = "program file name:";
//
Button3
//
This.button3.Location = new System.Drawing.Point (232, 192);
This.button3.Name = "Button3";
This.button3.Size = new System.Drawing.Size (128, 23);
This.button3.TabIndex = 13;
This.button3.Text = "Obtain this procedure file information";
This.button3.Click + = new System.EventHandler (This.button3_click);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (368, 222);
This. Controls.Add (This.button3);
This. Controls.Add (THIS.LABEL6);
This. Controls.Add (This.groupbox1);
This. Controls.Add (This.textbox1);
This. Controls.Add (This.button1);
This. Controls.Add (This.button2);
This. MaximizeBox = false;
This. Name = "Form1";
This. StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
This. Text = "Demo Get program file Information";
This.groupBox1.ResumeLayout (FALSE);
This. ResumeLayout (FALSE);

}
#endregion

<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}

private void Button1_Click (object sender, System.EventArgs e)
{//Browse Program Files
if (This.openFileDialog1.ShowDialog () ==dialogresult.ok)
{
This.textbox1.text=this.openfiledialog1.filename;
}
}

  private void button2_click (object sender, System.EventArgs e)
  {//get program file information
    string Myfilename=this.textbox1.text;
   if (myfilename.length<1)
     return;
    String shortname=myfilename.substring (Myfilename.lastindexof ("\") +1);
   this.groupbox1.text=shortname+ "program file Information";
   fileversioninfo Myinfo=fileversioninfo.getversioninfo (myfilename);
   this.label1.text= "Company name:" +myinfo.companyname;
   this.label2.text= "Product name:" +myinfo.productname;
   this.label3.text= "language mark:" +myinfo.language;
   this.label4.text= Version number: "+myinfo.fileversion;"
   this.label5.text= Copyright Notice: "+myinfo.legalcopyright;   
  }

private void Button3_Click (object sender, System.EventArgs e)
{//Get current program file information
this.groupbox1.text= "Display this procedure file information";
This.label1.text= "Company name:" +application.companyname;
this.label2.text= "Area information:" +application.currentculture;
this.label3.text= "Language sign:" +application.currentinputlanguage;
this.label4.text= "Product Name:" +application.productname;
this.label5.text= "Product version:" +application.productversion;
}
}
}

Original articles reproduced in this site must indicate the source http://www.111cn.net/net/net.html otherwise please do not reprint

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.