public static ComStorage CreateFileStorage(string filename, ComStorage.OpenMode openMode) { Util.ThrowOnNullArgument(filename, "filename"); ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes); object obj = null; ComStorage result; try { Guid iidistorage = Interop.IIDIStorage; int num = Interop.StgCreateStorageEx(filename, (uint)openMode, 0, 0U, IntPtr.Zero, IntPtr.Zero, ref iidistorage, out obj); if (num != 0) { throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename), num); } Interop.IStorage storage = obj as Interop.IStorage; if (storage == null) { throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename)); } obj = null; result = new ComStorage(storage); } finally { if (obj != null) { Marshal.ReleaseComObject(obj); } } return(result); }
public static ComStorage CreateStorageOnStream(Stream stream, ComStorage.OpenMode openMode) { Util.ThrowOnNullArgument(stream, "stream"); ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes); ComStorage comStorage = null; Interop.IStorage storage = null; try { LockBytesOnStream lockBytes = new LockBytesOnStream(stream); int num = Interop.StgCreateDocfileOnILockBytes(lockBytes, (uint)openMode, 0, out storage); if (num != 0) { throw new MsgStorageException(MsgStorageErrorCode.CreateStorageOnStreamFailed, MsgStorageStrings.FailedCreateStorage("ILockBytes"), num); } comStorage = new ComStorage(storage); } finally { if (comStorage == null && storage != null) { Marshal.ReleaseComObject(storage); } } return(comStorage); }
/// <summary> /// Opens a sub storage. Call this if an enumerated file object is of type storage /// </summary> /// <param name="parentStorage">parent storage of the sub storage file</param> /// <param name="storageName">name of the storage</param> /// <returns>Returns a reference to the sub storage</returns> public Interop.IStorage OpenSubStorage(Interop.IStorage parentStorage, string storageName) { if (parentStorage == null) { parentStorage = storage; } Interop.IStorage retObject = null; STATSTG sTATSTG; sTATSTG.pwcsName = storageName; sTATSTG.type = 1; try { Interop.IStorage iStorage = parentStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0); retObject = iStorage; } catch (Exception ex) { retObject = null; Trace.WriteLine("ITStorageWrapper.OpenSubStorage() - Failed for storage '" + storageName + "'"); Trace.Indent(); Trace.WriteLine("Exception: " + ex.Message); Trace.Unindent(); } return(retObject); }
/// <summary> /// Enumerates an Interop.IStorage object and creates the internal file object collection /// </summary> /// <param name="BasePath">Sets the base url for the storage files</param> /// <param name="enumStorage">storage to enumerate</param> protected void EnumIStorageObject(Interop.IStorage enumStorage, string BasePath) { Interop.IEnumSTATSTG iEnumSTATSTG; System.Runtime.InteropServices.ComTypes.STATSTG sTATSTG; int i; enumStorage.EnumElements(0, IntPtr.Zero, 0, out iEnumSTATSTG); iEnumSTATSTG.Reset(); while (iEnumSTATSTG.Next(1, out sTATSTG, out i) == (int)Interop.S_OK) { if (i == 0) { break; } FileObject newFileObj = new FileObject(); newFileObj.FileType = sTATSTG.type; switch (sTATSTG.type) { case 1: Interop.IStorage iStorage = enumStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0); if (iStorage != null) { string str = String.Concat(BasePath, sTATSTG.pwcsName.ToString()); newFileObj.FileStorage = iStorage; newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); foCollection.Add(newFileObj); EnumIStorageObject(iStorage, str); } break; case 2: System.Runtime.InteropServices.ComTypes.IStream uCOMIStream = enumStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); newFileObj.FileStream = uCOMIStream; foCollection.Add(newFileObj); break; case 4: Debug.WriteLine("Ignoring IProperty type ..."); break; case 3: Debug.WriteLine("Ignoring ILockBytes type ..."); break; default: Debug.WriteLine("Unknown object type ..."); break; } } }
public ComStorage OpenStorage(string storageName, ComStorage.OpenMode mode) { this.CheckDisposed("ComStorage::OpenStorage"); Util.ThrowOnNullArgument(storageName, "storageName"); ComStorage.CheckOpenMode(mode, "mode", ComStorage.validOpenModes); Interop.IStorage iOpenStorage = null; Util.InvokeComCall(MsgStorageErrorCode.FailedOpenSubstorage, delegate { this.iStorage.OpenStorage(storageName, null, (uint)mode, IntPtr.Zero, 0U, out iOpenStorage); }); return(new ComStorage(iOpenStorage)); }
/// <summary> /// Opens an UCOMIStream and returns the associated file object /// </summary> /// <param name="parentStorage">storage used to open the stream</param> /// <param name="fileName">filename of the stream</param> /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns> public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName) { if (parentStorage == null) { parentStorage = storage; } FileObject retObject = null; STATSTG sTATSTG; sTATSTG.pwcsName = fileName; sTATSTG.type = 2; try { retObject = new FileObject(); UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); if (uCOMIStream != null) { retObject.FileType = sTATSTG.type; retObject.FilePath = ""; retObject.FileName = sTATSTG.pwcsName.ToString(); retObject.FileStream = uCOMIStream; } else { retObject = null; } } catch (Exception ex) { retObject = null; Trace.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'"); Trace.Indent(); Trace.WriteLine("Exception: " + ex.Message); Trace.Unindent(); } return(retObject); }
private ComStorage(Interop.IStorage iStorage) { this.iStorage = iStorage; this.isDisposed = false; }
/// <summary> /// Enumerates an IStorage object and creates the file object collection /// </summary> /// <param name="stgEnum">IStorage to enumerate</param> public override void EnumIStorageObject(Interop.IStorage stgEnum) { base.EnumIStorageObject(storage); }
/// <summary> /// Enumerates an Interop.IStorage object and creates the internal file object collection /// </summary> /// <param name="stgEnum">Interop.IStorage to enumerate</param> public virtual void EnumIStorageObject(Interop.IStorage stgEnum) { EnumIStorageObject(stgEnum, ""); }
public static extern int StgCreateDocfileOnILockBytes([MarshalAs(UnmanagedType.Interface)][In] Interop.ILockBytes lockBytes, [In] uint grfMode, [In] int reserved, [MarshalAs(UnmanagedType.Interface)] out Interop.IStorage newStorage);
public static extern int StgOpenStorageOnILockBytes([MarshalAs(UnmanagedType.Interface)][In] Interop.ILockBytes lockBytes, [In] IntPtr pStgPriority, [In] uint grfMode, [In] IntPtr snbExclude, [In] uint reserved, [MarshalAs(UnmanagedType.Interface)] out Interop.IStorage newStorage);