/* ============================================================================== * 功能描述:RevitVisionUtil * 创 建 者:Garrett * 创建日期:2019/6/28 9:25:34 * ==============================================================================*/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ExportStart { /// /// RevitVisionUtil /// public class RevitVisionUtil { /// /// 获取Revit文件的版本 /// /// 文件路径 /// public static string GetRevitVision(string path) { string revitVision = null; FileStream stream = new FileStream(path, FileMode.Open); int size = 1024 * 1024; byte[] bytes = new byte[size]; while (stream.Read(bytes, 0, size) > 0) { string str = Encoding.Unicode.GetString(bytes); //if (str.Contains("2014")) //{ // revitVision = "2014"; // File.WriteAllText(@"D:\abc.txt", str); // System.Diagnostics.Process.Start("notepad.exe", path); // break; //} string pattern = @"Autodesk Revit \d{4}"; var match = Regex.Match(str, pattern); if (match.Success) { revitVision = match.Value.Substring(match.Length - 4, 4); //File.WriteAllText(@"D:\abc.txt", str); break; } } return revitVision; } } }