public bool WriteToRVTFile(string rvtFilePath, BasicFileInfo basicFileInfo) { if (!File.Exists(rvtFilePath)) { return(false); } StorageMode grfMode = StorageMode.ReadWrite | StorageMode.ShareExclusive; OleRootStorage oleRootStorage = new OleRootStorage(); string text = null; try { if (!oleRootStorage.Open(rvtFilePath, (int)grfMode)) { return(false); } var modelDataStreamIdentifier = new ModelDataStreamIdentifier(ModelDataStreamType.mdstBasicFileInfo); OleStream oleStream = oleRootStorage.OpenStream(modelDataStreamIdentifier.StreamName, grfMode); text = Path.GetTempFileName(); if (!WriteToStreamFile(text, basicFileInfo)) { return(false); } if (!oleStream.Import(text)) { return(false); } oleStream.Commit(); oleRootStorage.Commit(); } catch (Exception) { return(false); } finally { if (text != null) { try { File.Delete(text); } catch (Exception) { } } oleRootStorage.Close(isSave: true); } return(true); }
public BasicFileInfo ReadFromRVTFile(string rvtFilePath) { if (!File.Exists(rvtFilePath)) { return(null); } StorageMode grfMode = StorageMode.ReadWrite | StorageMode.ShareExclusive; OleRootStorage oleRootStorage = new OleRootStorage(); BasicFileInfo basicFileInfo = null; string text = null; try { if (!oleRootStorage.Open(rvtFilePath, (int)grfMode)) { return(null); } var modelDataStreamIdentifier = new ModelDataStreamIdentifier(ModelDataStreamType.mdstProjectInformation); OleStream oleStream = oleRootStorage.OpenStream(modelDataStreamIdentifier.StreamName, grfMode); text = Path.GetTempFileName(); if (!oleStream.Export(text)) { return(null); } return(ReadFromStreamFile(text)); } catch (Exception ex) { return(null); } finally { if (text != null) { try { File.Delete(text); } catch (Exception) { } } oleRootStorage.Close(isSave: false); } }