博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
项目中得到执行文件版本或其它信息
阅读量:4042 次
发布时间:2019-05-24

本文共 2188 字,大约阅读时间需要 7 分钟。

项目中我们有时会显示当前版本.

在这里插入图片描述
类文件:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;namespace DocumentSearch.Helper{
class FileInfoHelper {
/// /// get file path,include file name /// ///
DriveName:\path\****.EXE
public string GetFilePath() {
return this.GetType().Assembly.Location;//当前执行文件 path\name } public List GetFileInfo(string FileFullPathName) {
List list = new List(); FileInfo fileinfo = null; try {
fileinfo = new System.IO.FileInfo(FileFullPathName); if (fileinfo != null && fileinfo .Exists) {
System.Diagnostics.FileVersionInfo info = System.Diagnostics.FileVersionInfo.GetVersionInfo(FileFullPathName); list.Add(new {
FileName=info.FileName, FileVer = info.FileVersion, FileCreateDate = fileinfo.CreationTime.ToString("yyyy-MM-dd") }); //list.Add(new { FileVer = info.FileVersion }); //list.Add(new { ProductVer = info.ProductVersion }); Console.WriteLine("DisplayVer:" + info.ProductMajorPart + '.' + info.ProductMinorPart + '.' + info.ProductBuildPart + '.' + info.ProductPrivatePart); //list.Add(new { FileDesc = info.FileDescription }); //list.Add(new { FileName = System.Math.Ceiling(fileinfo.Length / 1024.0) + " KB" }); } return list; } catch (Exception ex) {
throw ex; } } }}

调用:

private void  frmMain_Load(object sender,EventArgs e)        {
//get file version date List listFileInfo = fileInfoHlp.GetFileInfo(fileInfoHlp.GetFilePath()); if (listFileInfo.Count > 0) {
**dynamic fileinfo = listFileInfo[0]; //使用dynamic类 this.Text = $"Main Form 【VerDate:{fileinfo.FileCreateDate}】";** } }

转载地址:http://nsmdi.baihongyu.com/

你可能感兴趣的文章
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>
用find命令查找最近修改过的文件
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
android raw读取超过1M文件的方法
查看>>
ubuntu下SVN服务器安装配置
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>