解压缩压缩富文本字段
Decompress Compress Rich Text field
我在包含压缩 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 抛出错误。有什么想法吗?
非常感谢。
我在包含压缩 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 抛出错误。有什么想法吗?
非常感谢。