C # Methods for obtaining information about program Files

Source: Internet
Author: User

This article describes the C # get program file related information method, share for everyone for your reference.

The implementation method is as follows:

Using system.reflection;using system.runtime.compilerservices;////general information about assemblies is controlled by the following//property set. Change these property values to modify the information associated with the assembly//. [Assembly:assemblytitle ("")][assembly:assemblydescription ("")][assembly:assemblyconfiguration ("")][assembly: Assemblycompany ("")][assembly:assemblyproduct ("")][assembly:assemblycopyright ("")][assembly:assemblytrademark ( "") The version information for the][assembly:assemblyculture ("")]////assembly consists of the following 4 values:////major Version//minor version//build number//revision number////You can specify all these values, or you can use the revision number and the The default value of the build number, by using ' * ' as follows//: [Assembly:assemblyversion ("1.0.*")]////to sign the assembly, you must specify the key to use. For more information about assembly signing, see the//Microsoft. NET Framework documentation. Use the following properties to control the key used for signing. Note://(*) If no key is specified, the assembly is not signed. (*) KeyName refers to a key that is already installed on the computer///cryptographic service Provider (CSP). KeyFile refers to a file that contains//keys. (*) If both the KeyFile and KeyName values are specified, the following processing occurs://(1) If the KeyName can be found in the CSP, the key is used. (2) If the KeyName does not exist and the keyfile exists, the key in the//keyfile is installed in the CSP and uses the key. (*) To create keyfile, you can use the Sn.exe (strong name) utility. When specifying KeyFile, the location of the keyfile should be relative to//project output directory, i.e.//%project directory%obj<configuration>. For exampleIf KeyFile is located in//the project directory, the assemblykeyfile//property should be specified as [Assembly:assemblykeyfile (": \.. \mykey.snk ")]//(*) delay signature is an advanced option-for more information about it, see the Microsoft. NET framework//documentation. [Assembly:assemblydelaysign (False)][assembly:assemblykeyfile ("")][assembly:assemblykeyname ("")]

Forms1.frm file here is the core program

Using system;using system.drawing;using system.collections;using system.componentmodel;using System.Windows.Forms; A summary description of the using system.data;using system.io;using system.diagnostics;namespace myfile{///<summary>///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 variables. </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 the resources that are in use. </summary>protected override void Dispose (bool disposing) {if (disposing) {if (= null) {COMPONENTS.D Ispose ();}} Base. Dispose (disposing);} #region the code generated by the Windows Forms Designer///<summary>///Designer supports the required method-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 (); SuspendLayout ();////button1//this.button1.location = new System.Drawing.Point (8, 192); this.button1.Name = "Button1"; This.button1.Size = new System.Drawing.Size (in a), This.button1.TabIndex = 1;this.button1.text = "Browse Program Files"; 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 (n.); This.textBox1.TabIndex = 2;this.textbox1.text = "";////Groupbox1//this.groupbox1.controls.add (This.label5); THIS.GROUPBOX1.CONTROLS.ADD ( THIS.LABEL4); Thi (www.jb51.net) s.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 (192); this.button2.Name =" Button2 "; this.button2.Size = new System.Drawing.Size (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 (+), 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 (+); this.label2.TabIndex = 1; This.label2.Text = "Product Name:";////label3//this.label3.location = new System.Drawing.Point (+); this.label3.Name = " Label3 "; this.label3.Size = new System.Drawing.Size (This.label3.TabIndex = 2;this.label3.text = "language mark:";////label4//this.label4.location = new System.Drawing.Point (+), 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 (+); this.label5.TabIndex = 4; This.label5.Text = "Copyright notice:";////label6//this.label6.location = new System.Drawing.Point (8, +); this.label6.Name = " Label6 "; this.label6.Size = new System.Drawing.Size (+ +); 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, This.button3.TabIndex = 13;this.button3.text = "Get this program file information"; This.button3.Click + = new System.EventHandler (This.button3_click);////form1//this. AutoScaleBaseSize = new System.drawinG.size (6, +); ClientSize = new System.Drawing.Size (368, 222); Controls.Add (This.button3); Controls.Add (THIS.LABEL6); Controls.Add (This.groupbox1); Controls.Add (This.textbox1); Controls.Add (This.button1); Controls.Add (This.button2); MaximizeBox = False;this. Name = "Form1"; StartPosition = System.windows.forms.formstartposition.centerscreen;this. Text = "Demo Get program file Information"; This.groupBox1.ResumeLayout (false); ResumeLayout (false);} #endregion The main entry point of the///<summary>///application. </summary>[stathread]static void Main () {Application.Run (New Form1 ());} private void Button1_Click (object sender, System.EventArgs e) {//Browse program file 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 flag:" +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= "Show this program file information"; This.label1.text= "Company Name:" +application.companyname;this.label2.text= "area information:" +application.currentculture; this.label3.text= "language mark:" +application.currentinputlanguage;this.label4.text= "Product Name:" +application.productname; this.label5.text= "Product version:" +application.productversion;}}}

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Methods for obtaining information about program Files

This address: http://www.paobuke.com/develop/c-develop/pbk23459.html






Related content C # List of common scenarios for implementing row to column example code for TCP communication for C # sockets talk about C # interface problems novice come to watch C # convert all filenames in the specified directory to lowercase
C # using the This keyword to implement a concatenation constructor call Method C # a way to read the Notepad data and write the database in a line-by-row element C # method of converting JPG to PDF C # method for implementing WinForm gradient effect

C # Methods for obtaining information about program Files

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.