本文整理汇总了C#中IStorage.Stat方法的典型用法代码示例。如果您正苦于以下问题:C# IStorage.Stat方法的具体用法?C# IStorage.Stat怎么用?C# IStorage.Stat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorage
的用法示例。
在下文中一共展示了IStorage.Stat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStreamFromPackage
private MemoryStream GetStreamFromPackage(IStorage storage, ExcelEncryption encryption)
{
MemoryStream ret=null;
comTypes.STATSTG statstg;
storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT);
IEnumSTATSTG pIEnumStatStg = null;
storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg);
comTypes.STATSTG[] regelt = { statstg };
uint fetched = 0;
uint res = pIEnumStatStg.Next(1, regelt, out fetched);
//if (regelt[0].pwcsName == "DataSpaces")
//{
// PrintStorage(storage, regelt[0],"");
//}
if (res == 0)
{
byte[] data;
EncryptionInfo encryptionInfo = null;
while (res != 1)
{
switch (statstg.pwcsName)
{
case "EncryptionInfo":
data = GetOleStream(storage, statstg);
//File.WriteAllBytes(@"c:\temp\EncInfo1.bin", data);
encryptionInfo = new EncryptionInfo();
encryptionInfo.ReadBinary(data);
encryption.Algorithm = encryptionInfo.Header.AlgID == AlgorithmID.AES128 ?
EncryptionAlgorithm.AES128 :
encryptionInfo.Header.AlgID == AlgorithmID.AES192 ?
EncryptionAlgorithm.AES192 :
EncryptionAlgorithm.AES256;
break;
case "EncryptedPackage":
data = GetOleStream(storage, statstg);
ret = DecryptDocument(data, encryptionInfo, encryption.Password);
break;
}
if ((res = pIEnumStatStg.Next(1, regelt, out fetched)) != 1)
{
statstg = regelt[0];
}
}
}
Marshal.ReleaseComObject(pIEnumStatStg);
return ret;
}
示例2: ReadParts
private MemoryStream ReadParts(IStorage storage, StoragePart storagePart)
{
MemoryStream ret = null;
comTypes.STATSTG statstg;
storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT);
IEnumSTATSTG pIEnumStatStg = null;
storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg);
comTypes.STATSTG[] regelt = { statstg };
uint fetched = 0;
uint res = pIEnumStatStg.Next(1, regelt, out fetched);
//if (regelt[0].pwcsName == "DataSpaces")
//{
// PrintStorage(storage, regelt[0],"");
//}
while (res != 1)
{
foreach (var item in regelt)
{
if (item.type == 1)
{
IStorage subStorage;
storage.OpenStorage(item.pwcsName, null, STGM.DIRECT | STGM.READ | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out subStorage);
StoragePart subStoragePart=new StoragePart();
storagePart.SubStorage.Add(item.pwcsName, subStoragePart);
ReadParts(subStorage, subStoragePart);
}
else
{
storagePart.DataStreams.Add(item.pwcsName, GetOleStream(storage, item));
}
}
res = pIEnumStatStg.Next(1, regelt, out fetched);
}
Marshal.ReleaseComObject(pIEnumStatStg);
return ret;
}
示例3: CreateOnIStorage
/// <summary>
/// This will create a container StorageRoot based on the given IStorage
/// interface
/// </summary>
/// <param name="root">The new IStorage (RCW) upon which to build the new StorageRoot</param>
/// <returns>New StorageRoot object built on the given IStorage</returns>
private static StorageRoot CreateOnIStorage( IStorage root )
{
// The root is created by calling unmanaged CompoundFile APIs. The return value from the call is always
// checked to see if is S_OK. If it is S_OK, the root should never be null. However, just to make sure
// call Invariant.Assert
Invariant.Assert(root != null);
System.Runtime.InteropServices.ComTypes.STATSTG rootSTAT;
bool readOnly;
root.Stat( out rootSTAT, SafeNativeCompoundFileConstants.STATFLAG_NONAME );
readOnly =( SafeNativeCompoundFileConstants.STGM_WRITE != ( rootSTAT.grfMode & SafeNativeCompoundFileConstants.STGM_WRITE ) &&
SafeNativeCompoundFileConstants.STGM_READWRITE != (rootSTAT.grfMode & SafeNativeCompoundFileConstants.STGM_READWRITE) );
return new StorageRoot( root, readOnly );
}