我在包含压缩的RichText数据的数据表中有一个image列。我想这是从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抛出错误。有什么想法吗?
非常感谢。
答案 0 :(得分:0)