/// <summary> /// 打开文件 /// </summary> /// <param name="path">文件路径</param> public void Open(string path) { FileDetailInfo info = new FileDetailInfo(path); if (this.SetDisplayAction != null) { this.SetDisplayAction(this.PART_RichTextBox, info); } else { double toMb = 1024d * 1024d; string display = "文件名称:" + info.FileName + Environment.NewLine + "文件全称:" + info.FullFileName + Environment.NewLine + "文件大小:" + Math.Round(info.FileLength / toMb, 2, MidpointRounding.AwayFromZero) + " MB ( " + info.FileLength + " 字节 )" + Environment.NewLine + "文件目录:" + info.FileDirectory + Environment.NewLine + "创建时间:" + info.FileCreationDate + Environment.NewLine + "修改时间:" + info.FileModification + Environment.NewLine + "文件类型:" + info.FileType + Environment.NewLine + "文件分类:" + info.FileCategory; this.PART_RichTextBox.Document.Blocks.Clear(); Paragraph p = new Paragraph(); p.LineHeight = this.FontSize * 1.5; p.Inlines.Add(display); this.PART_RichTextBox.Document.Blocks.Add(p); } this.OpenArgs = path; }
public void OpenEx(string path, string displayPath) { FileDetailInfo info = new FileDetailInfo(path); if (this.SetDisplayAction != null) { this.SetDisplayAction(this.PART_RichTextBox, info); } else { string tmpPath = displayPath.IsNullOrEmptyOrWhiteSpace() ? info.FullFileName : displayPath; string tmpDir = string.Empty; if (tmpPath != null) { var index = tmpPath.LastIndexOf(@"\"); if (index > -1) { tmpDir = tmpPath.Substring(0, tmpPath.LastIndexOf(@"\")); } else { tmpDir = info.FileDirectory; } } string sizeStr; if (info.FileType == "文件夹") { sizeStr = string.Empty; } else { sizeStr = System.Utility.Helper.File.GetFileSize(info.FileLength); } string display = "文件名称:" + info.FileName + Environment.NewLine + "文件全称:" + tmpPath + Environment.NewLine + "文件大小:" + sizeStr + Environment.NewLine + "文件目录:" + tmpDir + Environment.NewLine + "创建时间:" + info.FileCreationDate + Environment.NewLine + "修改时间:" + info.FileModification + Environment.NewLine + "文件类型:" + info.FileType + Environment.NewLine + "文件分类:" + info.FileCategory; this.PART_RichTextBox.Document.Blocks.Clear(); Paragraph p = new Paragraph(); p.LineHeight = this.FontSize * 1.5; p.Inlines.Add(display); this.PART_RichTextBox.Document.Blocks.Add(p); } this.OpenArgs = path; }