Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than ole32, prefix the name with the module name and a period.
The System.IO.Packaging namespace contains public StorageInfo and StreamInfo classes that encapsulate OLE structured storage access. Unfortunately, the StorageRoot class, which is needed to create or open the files, is an internal class. However, you can use reflection to access the methods on StorageRoot if necessary. The code below will open a storage file and convert it to XML where each stream is hex encoded.
public static void ReadOSSFile(string fileName, XmlWriter writer)
{
int checkResult = StgIsStorageFile(fileName);
Preconditions.RequireArgument(checkResult == 0,
"The specified file is not an OLE Structured Storage file.");
private static object InvokeStorageRootMethod(StorageInfo storageRoot, string methodName, params object[] methodArgs)
{
//We need the StorageRoot class to directly open an OSS file. Unfortunately, it's internal.
//So we'll have to use Reflection to access it. This code was inspired by:
//http://henbo.spaces.live.com/blog/cns!2E073207A544E12!200.entry
//Note: In early WinFX CTPs the StorageRoot class was public because it was documented
//here: http://msdn2.microsoft.com/en-us/library/aa480157.aspx
private static string ConvertStreamBytesToHex(StreamInfo streamInfo)
{
using (Stream streamReader = streamInfo.GetStream(FileMode.Open, FileAccess.Read))
{
StringBuilder sb = new StringBuilder();
int currentRead;
while ((currentRead = streamReader.ReadByte()) >= 0)
{
byte currentByte = (byte)currentRead;
sb.AppendFormat("{0:X2}", currentByte);
}
return sb.ToString();
}
}
[DllImport("ole32.dll", CharSet = CharSet.Unicode)]
private static extern int StgIsStorageFile(string fileName);
Click to read this page
5/16/2017 3:40:12 AM - anonymous
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).