通過 .NET 管理 Microsoft® Visio 文件元數據
使用服務器端 .NET API 查看、添加、更新、刪除或提取內置和自定義 Visio 文件屬性。
.NET Visio API 支持標題、作者姓名、文檔統計等系統定義(內置)屬性以及名稱-值對形式的用戶定義(自定義)屬性的管理。有 Diagram 類 加載文件,以及 頁面集合 處理頁面的集合以及 頁麵類 用於表示單個頁面。與這些類、文檔屬性一起,customprops 使元數據管理的過程變得簡單。
管理內置屬性
為了管理系統定義的屬性,API 提供 文檔屬性 , 程序員可以輕鬆訪問內置屬性並更新其值。
C# 管理內置屬性的代碼
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Shapes(); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Display Visio version and document modification time at different stages | |
Console.WriteLine("Visio Instance Version : " + diagram.Version); | |
Console.WriteLine("Full Build Number Created : " + diagram.DocumentProps.BuildNumberCreated); | |
Console.WriteLine("Full Build Number Edited : " + diagram.DocumentProps.BuildNumberEdited); | |
Console.WriteLine("Date Created : " + diagram.DocumentProps.TimeCreated); | |
Console.WriteLine("Date Last Edited : " + diagram.DocumentProps.TimeEdited); | |
Console.WriteLine("Date Last Printed : " + diagram.DocumentProps.TimePrinted); | |
Console.WriteLine("Date Last Saved : " + diagram.DocumentProps.TimeSaved); | |
Console.WriteLine("CustomProps Length " + diagram.DocumentProps.CustomProps.Count); |
管理自定義屬性
為了管理用戶定義的屬性,API 提供 自定義道具 ,開發人員可以輕鬆訪問已添加的屬性以及添加新屬性。為了添加自定義屬性, 添加方法 添加屬性並返回新屬性的引用作為 自定義道具 目的。 CustomProp 類用於檢索文檔屬性的名稱、值和類型,如 姓名 , 自定義值 , 財產類型 枚舉值。
C# 在 Visio 文件中添加元數據的代碼
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Shapes(); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Get CustomProperties of diagram | |
Aspose.Diagram.CustomPropCollection customProperties = diagram.DocumentProps.CustomProps; | |
//Set property of CustomProp | |
Aspose.Diagram.CustomProp customProp = new Aspose.Diagram.CustomProp(); | |
customProp.PropType = Aspose.Diagram.PropType.String; | |
customProp.CustomValue.ValueString = "Test"; | |
//Add CustomProp to Collection | |
customProperties.Add(customProp); |