public static int GetFileFormat(byte[] aBuffer) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (aBuffer.Length == 0) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else { format = GetFileFormatBySignature(aBuffer); if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(ms); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { if (Ionic.Zip.ZipFile.IsZipFile(ms, false)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(aBuffer)) { format = GetFileFormatByZip(oZipFile); } } } } catch { } } } } } catch { } return(format); }
public static FileType GetOleFileType(System.IO.Stream stream) { FileType type = FileType.Unknown; using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(stream)) { type = GetOleFileType(cf.RootStorage); } return(type); }
public static FileType GetOleFileType(byte [] data) { FileType type = FileType.Unknown; System.IO.MemoryStream stream = new System.IO.MemoryStream(data); using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(stream)) { type = GetOleFileType(cf.RootStorage); } return(type); }
private static int GetFileFormatStorage(OpenMcdf.CompoundFile oCompoundFile) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { oCompoundFile.RootStorage.GetStream("WordDocument"); format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC; } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { oCompoundFile.RootStorage.GetStream("Workbook"); format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS; } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { oCompoundFile.RootStorage.GetStream("PowerPoint Document"); format = FileFormats.AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT; } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { oCompoundFile.RootStorage.GetStorage("\x0006DataSpaces"); format = FileFormats.AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO; } catch { } } return(format); }
public PSTProcessingResult ProcessQueueObject() { bool issuccessful = false; switch (this.Type) { case FileParserType.Ole: using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(this.FileToProcess)) { } break; } PSTProcessingResult result = new PSTProcessingResult() { IsSuccessful = issuccessful, Filename = this.FileToProcess + ".xml" }; result.SetProcessingObject <FileParser>(this); return(result); }
public static int GetFileFormat(string sPath) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (new FileInfo(sPath).Length == 0) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else { using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { byte[] aBuffer = new byte[100]; fs.Read(aBuffer, 0, aBuffer.Length); format = GetFileFormatBySignature(aBuffer); } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(sPath); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { if (Ionic.Zip.ZipFile.IsZipFile(sPath)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(sPath)) { format = GetFileFormatByZip(oZipFile); } } } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { string sExtention = Path.GetExtension(sPath).ToLower(); if (".mht" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; else if (".txt" == sExtention || ".xml" == sExtention || ".xslt" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else if (".csv" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; else if (".svg" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG; else if (".html" == sExtention || ".htm" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; else { string sExt = Path.GetExtension(sPath); if (sExt.Length > 0 && '.' == sExt[0]) sExt = sExt.Substring(1); format = FileFormats.FromString(sExt); } } } } } catch { } return format; }
public static int GetFileFormat(byte[] aBuffer) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (aBuffer.Length == 0) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else { format = GetFileFormatBySignature(aBuffer); if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(ms); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { if (Ionic.Zip.ZipFile.IsZipFile(ms, false)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(aBuffer)) { format = GetFileFormatByZip(oZipFile); } } } } catch { } } } } } catch { } return format; }
private void ParseFile(string filename, uint depth, ref System.Collections.Generic.List <string> outputfiles) { KRSrcWorkflow.WFFileType.FileType type = KRSrcWorkflow.WFFileType.GetFileType(filename); if (type == KRSrcWorkflow.WFFileType.FileType.OlePowerPoint) { uint fileidx = 0; System.Collections.Generic.List <string> pptfiles = new System.Collections.Generic.List <string>(); DIaLOGIKa.b2xtranslator.StructuredStorage.Reader.StructuredStorageReader ssr = new DIaLOGIKa.b2xtranslator.StructuredStorage.Reader.StructuredStorageReader(filename); DIaLOGIKa.b2xtranslator.PptFileFormat.PowerpointDocument ppt = new DIaLOGIKa.b2xtranslator.PptFileFormat.PowerpointDocument(ssr); foreach (uint persistId in ppt.PersistObjectDirectory.Keys) { UInt32 offset = ppt.PersistObjectDirectory[persistId]; ppt.PowerpointDocumentStream.Seek(offset, System.IO.SeekOrigin.Begin); DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleObjStgAtom obj = DIaLOGIKa.b2xtranslator.OfficeDrawing.Record.ReadRecord(ppt.PowerpointDocumentStream) as DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleObjStgAtom; if (obj != null) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, KRSrcWorkflow.WFUtilities.GetNextDirectoryNumber(System.IO.Directory.GetParent(filename).FullName)); if (!System.IO.Directory.Exists(filedir)) { System.IO.Directory.CreateDirectory(filedir); } if (System.IO.Directory.Exists(filedir)) { byte[] data = obj.DecompressData(); System.IO.MemoryStream ms = new System.IO.MemoryStream(data); KRSrcWorkflow.WFFileType.FileType oletype = KRSrcWorkflow.WFFileType.GetOleFileType(data); if (oletype == WFFileType.FileType.OlePackage || oletype == WFFileType.FileType.OleContents) { using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(ms)) { WriteStorage(cf.RootStorage, filedir, depth, ref pptfiles); } } else { string filenm = String.Format("{0}\\pptembed{1}", filedir, fileidx); using (System.IO.FileStream fs = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { byte[] buffer = new byte[1024]; int len; while ((len = ms.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, len); } pptfiles.Add(filenm); } fileidx++; ms.Close(); ms.Dispose(); } } } } #if false foreach (DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleEmbedContainer ole in ppt.OleObjects.Values) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, diridx++); if (!System.IO.Directory.Exists(filedir)) { System.IO.Directory.CreateDirectory(filedir); } if (System.IO.Directory.Exists(filedir)) { string filenm = String.Format("{0}\\pptembed{1}", filedir, ole.SiblingIdx); try { System.IO.FileStream fss = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write); byte[] data = ole.stgAtom.DecompressData(); fss.Write(data, 0, data.Length); fss.Flush(); fss.Close(); fss.Dispose(); pptfiles.Add(filenm); } catch (Exception ex) { } } } #endif foreach (DIaLOGIKa.b2xtranslator.OfficeDrawing.Record record in ppt.PicturesContainer._pictures.Values) //.Where(x => x.TypeCode == 0xF01C || x.TypeCode == 0xF01D || x.TypeCode == 0xF01E || x.TypeCode == 0xF01F || x.TypeCode == 0xF029 || x.TypeCode == 0xF02A)) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, "PPTPictures"); //, KRSrcWorkflow.WFUtilities.GetNextDirectoryNumber(System.IO.Directory.GetParent(filename).FullName)); if (!System.IO.Directory.Exists(filedir)) { System.IO.Directory.CreateDirectory(filedir); } if (System.IO.Directory.Exists(filedir)) { string extension = string.Empty; int skip = 0; switch (record.TypeCode) { case 0xF01A: extension = ".emf"; break; case 0xF01B: extension = ".wmf"; break; case 0xF01C: extension = ".pict"; break; case 0xF01D: case 0xF02A: extension = ".jpg"; skip = 17; break; case 0xF01E: extension = ".png"; skip = 17; break; case 0xF01F: extension = ".dib"; break; case 0xF029: extension = ".tiff"; break; } string filenm = String.Format("{0}\\pptembed{1}{2}", filedir, fileidx++, extension); using (System.IO.FileStream fs = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { // need to skip 17 byte header in raw data stream byte[] data = ((extension == ".emf" || extension == ".wmf")) ? ((DIaLOGIKa.b2xtranslator.OfficeDrawing.MetafilePictBlip)record).Decrompress() : record.RawData.Skip(skip).ToArray(); fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); fs.Dispose(); pptfiles.Add(filenm); } } } ssr.Close(); ssr.Dispose(); outputfiles.AddRange(pptfiles); depth--; if (depth > 0) { foreach (string fn in pptfiles) { ParseFile(fn, depth, ref outputfiles); } } } else { using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(filename)) { WriteStorage(cf.RootStorage, System.IO.Directory.GetParent(filename).FullName, depth, ref outputfiles); } } }
private void WriteStorage(OpenMcdf.CFStorage cfstorage, string directory, uint depth, ref System.Collections.Generic.List <string> outputfiles) { KRSrcWorkflow.WFFileType.FileType type = KRSrcWorkflow.WFFileType.GetOleFileType(cfstorage); if ((cfstorage.Name != "Root Entry") || ((cfstorage.Name == "Root Entry") && (type == KRSrcWorkflow.WFFileType.FileType.OlePackage || type == KRSrcWorkflow.WFFileType.FileType.OleContents))) { string filename = string.Empty; if (type == KRSrcWorkflow.WFFileType.FileType.OlePackage) { Ole10Native olenative = new Ole10Native(new System.IO.MemoryStream(cfstorage.GetStream(Convert.ToChar((byte)1).ToString() + "Ole10Native").GetData())); filename = olenative.FileName; int idx = olenative.FileName.LastIndexOf("\\"); if (idx != -1) { filename = olenative.FileName.Substring(idx + 1); } filename = String.Format("{0}\\{1}", directory, filename); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { fs.Write(olenative.NativeData, 0, olenative.NativeData.Length); } } else if (type == KRSrcWorkflow.WFFileType.FileType.OleContents) { filename = String.Format("{0}\\{1}", directory, "contents"); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { byte [] data = cfstorage.GetStream("CONTENTS").GetData(); fs.Write(data, 0, data.Length); } } else { OpenMcdf.CompoundFile tmp = new OpenMcdf.CompoundFile(); Write(tmp.RootStorage, cfstorage); filename = String.Format("{0}\\{1}", directory, cfstorage.Name); tmp.Save(filename); tmp.Close(); } outputfiles.Add(filename); } if (depth == 0) { return; } depth--; if (type == KRSrcWorkflow.WFFileType.FileType.OleWord || type == WFFileType.FileType.OlePublisher) { try { OpenMcdf.CFStorage objectpool = cfstorage.GetStorage(type == KRSrcWorkflow.WFFileType.FileType.OleWord ? "ObjectPool" : "Objects"); if (objectpool != null) { cfstorage = objectpool; } } catch (Exception) { } } if (cfstorage != null) { foreach (OpenMcdf.CFItem item in cfstorage.EnumChildren.Where(x => x.IsStorage)) { string filedir = string.Format("{0}\\{1}", directory, KRSrcWorkflow.WFUtilities.GetNextDirectoryNumber(directory)); if (!System.IO.Directory.Exists(filedir)) { System.IO.Directory.CreateDirectory(filedir); } if (System.IO.Directory.Exists(filedir)) { WriteStorage((OpenMcdf.CFStorage)item, filedir, depth, ref outputfiles); } } } }
public static int GetFileFormat(string sPath) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (new FileInfo(sPath).Length == 0) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else { using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { byte[] aBuffer = new byte[100]; fs.Read(aBuffer, 0, aBuffer.Length); format = GetFileFormatBySignature(aBuffer); } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(sPath); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { if (Ionic.Zip.ZipFile.IsZipFile(sPath)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(sPath)) { format = GetFileFormatByZip(oZipFile); } } } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { string sExtention = Path.GetExtension(sPath).ToLower(); if (".mht" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; } else if (".txt" == sExtention || ".xml" == sExtention || ".xslt" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else if (".csv" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; } else if (".svg" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG; } else if (".html" == sExtention || ".htm" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; } } } } } catch { } return(format); }
private void ParseFile(string filename, uint depth, ref System.Collections.Generic.List<string> outputfiles) { SFWorkflow.WFFileType.FileType type = SFWorkflow.WFFileType.GetFileType(filename); if (type == SFWorkflow.WFFileType.FileType.OlePowerPoint) { uint fileidx = 0; System.Collections.Generic.List<string> pptfiles = new System.Collections.Generic.List<string>(); DIaLOGIKa.b2xtranslator.StructuredStorage.Reader.StructuredStorageReader ssr = new DIaLOGIKa.b2xtranslator.StructuredStorage.Reader.StructuredStorageReader(filename); DIaLOGIKa.b2xtranslator.PptFileFormat.PowerpointDocument ppt = new DIaLOGIKa.b2xtranslator.PptFileFormat.PowerpointDocument(ssr); foreach (uint persistId in ppt.PersistObjectDirectory.Keys) { UInt32 offset = ppt.PersistObjectDirectory[persistId]; ppt.PowerpointDocumentStream.Seek(offset, System.IO.SeekOrigin.Begin); DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleObjStgAtom obj = DIaLOGIKa.b2xtranslator.OfficeDrawing.Record.ReadRecord(ppt.PowerpointDocumentStream) as DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleObjStgAtom; if (obj != null) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, SFWorkflow.WFUtilities.GetNextDirectoryNumber(System.IO.Directory.GetParent(filename).FullName)); if (!System.IO.Directory.Exists(filedir)) System.IO.Directory.CreateDirectory(filedir); if (System.IO.Directory.Exists(filedir)) { byte[] data = obj.DecompressData(); System.IO.MemoryStream ms = new System.IO.MemoryStream(data); SFWorkflow.WFFileType.FileType oletype = SFWorkflow.WFFileType.GetOleFileType(data); if (oletype == WFFileType.FileType.OlePackage || oletype == WFFileType.FileType.OleContents) { using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(ms)) { WriteStorage(cf.RootStorage, filedir, depth, ref pptfiles); } } else { string filenm = String.Format("{0}\\pptembed{1}", filedir, fileidx); using (System.IO.FileStream fs = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { byte[] buffer = new byte[1024]; int len; while ((len = ms.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, len); } pptfiles.Add(filenm); } fileidx++; ms.Close(); ms.Dispose(); } } } } #if false foreach (DIaLOGIKa.b2xtranslator.PptFileFormat.ExOleEmbedContainer ole in ppt.OleObjects.Values) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, diridx++); if (!System.IO.Directory.Exists(filedir)) System.IO.Directory.CreateDirectory(filedir); if (System.IO.Directory.Exists(filedir)) { string filenm = String.Format("{0}\\pptembed{1}", filedir, ole.SiblingIdx); try { System.IO.FileStream fss = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write); byte[] data = ole.stgAtom.DecompressData(); fss.Write(data, 0, data.Length); fss.Flush(); fss.Close(); fss.Dispose(); pptfiles.Add(filenm); } catch (Exception ex) { } } } #endif foreach (DIaLOGIKa.b2xtranslator.OfficeDrawing.Record record in ppt.PicturesContainer._pictures.Values) //.Where(x => x.TypeCode == 0xF01C || x.TypeCode == 0xF01D || x.TypeCode == 0xF01E || x.TypeCode == 0xF01F || x.TypeCode == 0xF029 || x.TypeCode == 0xF02A)) { string filedir = string.Format("{0}\\{1}", System.IO.Directory.GetParent(filename).FullName, "PPTPictures"); //, SFWorkflow.WFUtilities.GetNextDirectoryNumber(System.IO.Directory.GetParent(filename).FullName)); if (!System.IO.Directory.Exists(filedir)) System.IO.Directory.CreateDirectory(filedir); if (System.IO.Directory.Exists(filedir)) { string extension = string.Empty; int skip = 0; switch (record.TypeCode) { case 0xF01A: extension = ".emf"; break; case 0xF01B: extension = ".wmf"; break; case 0xF01C: extension = ".pict"; break; case 0xF01D: case 0xF02A: extension = ".jpg"; skip = 17; break; case 0xF01E: extension = ".png"; skip = 17; break; case 0xF01F: extension = ".dib"; break; case 0xF029: extension = ".tiff"; break; } string filenm = String.Format("{0}\\pptembed{1}{2}", filedir, fileidx++, extension); using(System.IO.FileStream fs = new System.IO.FileStream(filenm, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { // need to skip 17 byte header in raw data stream byte[] data = ((extension == ".emf" || extension == ".wmf")) ? ((DIaLOGIKa.b2xtranslator.OfficeDrawing.MetafilePictBlip)record).Decrompress() : record.RawData.Skip(skip).ToArray(); fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); fs.Dispose(); pptfiles.Add(filenm); } } } ssr.Close(); ssr.Dispose(); outputfiles.AddRange(pptfiles); depth--; if (depth > 0) { foreach(string fn in pptfiles) ParseFile(fn, depth, ref outputfiles); } } else { using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(filename)) { WriteStorage(cf.RootStorage, System.IO.Directory.GetParent(filename).FullName, depth, ref outputfiles); } } }
private void WriteStorage(OpenMcdf.CFStorage cfstorage, string directory, uint depth, ref System.Collections.Generic.List<string> outputfiles) { SFWorkflow.WFFileType.FileType type = SFWorkflow.WFFileType.GetOleFileType(cfstorage); if ((cfstorage.Name != "Root Entry") || ((cfstorage.Name == "Root Entry") && (type == SFWorkflow.WFFileType.FileType.OlePackage || type == SFWorkflow.WFFileType.FileType.OleContents))) { string filename = string.Empty; if (type == SFWorkflow.WFFileType.FileType.OlePackage) { Ole10Native olenative = new Ole10Native(new System.IO.MemoryStream(cfstorage.GetStream(Convert.ToChar((byte)1).ToString() + "Ole10Native").GetData())); filename = olenative.FileName; int idx = olenative.FileName.LastIndexOf("\\"); if (idx != -1) filename = olenative.FileName.Substring(idx + 1); filename = String.Format("{0}\\{1}", directory, filename); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { fs.Write(olenative.NativeData, 0, olenative.NativeData.Length); } } else if (type == SFWorkflow.WFFileType.FileType.OleContents) { filename = String.Format("{0}\\{1}", directory, "contents"); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { byte [] data = cfstorage.GetStream("CONTENTS").GetData(); fs.Write(data, 0, data.Length); } } else { OpenMcdf.CompoundFile tmp = new OpenMcdf.CompoundFile(); Write(tmp.RootStorage, cfstorage); filename = String.Format("{0}\\{1}", directory, cfstorage.Name); tmp.Save(filename); tmp.Close(); } outputfiles.Add(filename); } if (depth == 0) return; depth--; if (type == SFWorkflow.WFFileType.FileType.OleWord || type == WFFileType.FileType.OlePublisher) { try { OpenMcdf.CFStorage objectpool = cfstorage.GetStorage(type == SFWorkflow.WFFileType.FileType.OleWord ? "ObjectPool" : "Objects"); if (objectpool != null) cfstorage = objectpool; } catch (Exception) { } } if (cfstorage != null) { foreach (OpenMcdf.CFItem item in cfstorage.EnumChildren.Where(x => x.IsStorage)) { string filedir = string.Format("{0}\\{1}", directory, SFWorkflow.WFUtilities.GetNextDirectoryNumber(directory)); if (!System.IO.Directory.Exists(filedir)) System.IO.Directory.CreateDirectory(filedir); if (System.IO.Directory.Exists(filedir)) WriteStorage((OpenMcdf.CFStorage)item, filedir, depth, ref outputfiles); } } }
public static FileType GetOleFileType(System.IO.Stream stream) { FileType type = FileType.Unknown; using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(stream)) { type = GetOleFileType(cf.RootStorage); } return type; }
public static FileType GetOleFileType(byte [] data) { FileType type = FileType.Unknown; System.IO.MemoryStream stream = new System.IO.MemoryStream(data); using (OpenMcdf.CompoundFile cf = new OpenMcdf.CompoundFile(stream)) { type = GetOleFileType(cf.RootStorage); } return type; }