using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.IO; using System.Collections.Generic; namespace SeFileProps { public class PropsClosedFiles { SolidEdgeFileProperties.PropertySets propertySets = null; SolidEdgeFileProperties.Properties properties = null; SolidEdgeFileProperties.Property property = null; string format2 = "{0} = {1}"; public PropsClosedFiles() { } [STAThread] public int ReadStatusSingleFile(FileInfo file) { int result = -1; try { // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file propertySets.Open(file.FullName, false); properties = (SolidEdgeFileProperties.Properties)propertySets["ExtendedSummaryInformation"]; property = (SolidEdgeFileProperties.Property)properties["Status"]; result = (int)property.Value; } catch { } finally { ReleaseObjects(); } return result; } public bool SaveStatusSingleFile(FileInfo file, int status) { bool result = false; // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file try { propertySets.Open(file.FullName, false); properties = (SolidEdgeFileProperties.Properties)propertySets["ExtendedSummaryInformation"]; property = (SolidEdgeFileProperties.Property)properties["Status"]; property.Value = status; propertySets.Save(); result = true; } catch { } finally { ReleaseObjects(); } return result; } public string SaveStatusMultipleFiles(List files, int status) { string result = ""; // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file foreach (FileInfo item in files) { try { propertySets.Open(item.FullName, false); properties = (SolidEdgeFileProperties.Properties)propertySets["ExtendedSummaryInformation"]; property = (SolidEdgeFileProperties.Property)properties["Status"]; property.Value = status; propertySets.Save(); } catch { } finally { ReleaseObjects(); } } return result; } private void ReleaseObjects() { if (property != null) { Marshal.ReleaseComObject(property); property = null; } if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; } if (propertySets != null) { propertySets.Close(); Marshal.ReleaseComObject(propertySets); propertySets = null; } } public void test() { try { // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file propertySets.Open(@"\\wengerag.local\CAD-Daten$\CAD-3D Server\705 Hasler Roboterzelle Stäubli Türbänder Chiron\705-1000 Roboter\2564-1236 Testteil.par", true); // Example: Loop through all properties // Note that indexes are zero based for (int i = 0; i < propertySets.Count; i++) { properties = (SolidEdgeFileProperties.Properties)propertySets[i]; // Note that indexes are zero based for (int j = 0; j < properties.Count; j++) { property = (SolidEdgeFileProperties.Property)properties[j]; try { Debug.WriteLine(string.Format(format2, property.Name, property.Value)); } catch { Debug.WriteLine(string.Format(format2, property.Name, "ERROR")); } } } // Get a reference to the SummaryInformation properties properties = (SolidEdgeFileProperties.Properties) propertySets["SummaryInformation"]; // Get a reference to the Title property by name property = (SolidEdgeFileProperties.Property) properties["Title"]; } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } finally { ReleaseObjects(); } } } }