解压压缩富文本字段
本文关键字:文本 字段 压缩 | 更新日期: 2023-09-27 18:02:24
我有一个包含压缩RichText数据的数据表中的图像列。我想这是从Outlook (PR_RTF_COMPRESSED属性或其他东西)获得的。我需要把它解压。使用c#,我正在尝试以下内容,但我得到一个System.Runtime.InteropServices.COMExceptions,无法找出它。
我发现一些旧的链接问这个问题,没有解决的答案。下面是我使用c#编写的代码片段。
public Form1()
{
InitializeComponent();
IStream streamOut;
string con = "connection string";
SqlCommand command = new SqlCommand("select top 10 columnInCompressedRichTextFormat FROM tableWithCompressedRichTextData", new SqlConnection(dbConnectionString));
DataTable x = new DataTable();
SqlDataAdapter a = new SqlDataAdapter(command);
a.Fill(x);
a.Dispose();
foreach (DataRow r in dtResults.Rows)
{
byte[] arrayOfBytes = (byte[]) r["columnInCompressedRichTextFormat"];
IStream i = CreateIStreamFromBytes(arrayOfBytes);
WrapCompressedRTFStream(input, 0, out streamOut);
}
}
public IStream CreateIStreamFromBytes(byte[] bytes)
{
IntPtr hglobal = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, hglobal, bytes.Length);
IStream stream = null;
CreateStreamOnHGlobal(hglobal, true, out stream);
return stream;
}
[DllImport("Mapi32.dll", PreserveSig = false)]
private static extern void
WrapCompressedRTFStream(
[MarshalAs(UnmanagedType.Interface)] IStream lpCompressedRTFStream,
uint ulflags,
[MarshalAs(UnmanagedType.Interface)] out IStream lpUncompressedRTFStream
);
[DllImport("ole32.dll", PreserveSig = false)]
static extern int CreateStreamOnHGlobal(IntPtr hGlobal,
[MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease,
[MarshalAs(UnmanagedType.Interface)] out IStream ppstm
);
public const uint MAPI_MODIFY = 0x00000001;
public const uint STORE_UNCOMPRESSED_RTF = 0x00008000;
}
WrapCompressedRTFStream抛出错误。什么好主意吗?
许多谢谢。一个完全不同的方法,似乎工作-http://www.vbforums.com/showthread.php?669883-NET-3-5-RtfDecompressor-Decompress-RTF-From-Outlook-And-Exchange-Server