Windows Vista 和 Office: 使用托管预览处理程序框架以自己的方式查看数据
2009-02-09 17:43:48 来源:WEB开发网[PreviewHandler("ZIP Preview Handler", ".zip",
"{c0a64ec6-729b-442d-88ce-d76a9fc69e44}")]
[ProgId("MsdnMag.ZipPreviewHandler")]
[Guid("853f35e3-bd13-417b-b859-1df25be6c834")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public sealed class ZipPreviewHandler : FileBasedPreviewHandler
{
protected override PreviewHandlerControl CreatePreviewHandlerControl()
{
return new ZipPreviewHandlerControl();
}
private sealed class ZipPreviewHandlerControl :
FileBasedPreviewHandlerControl
{
public override void Load(FileInfo file)
{
ListView listView = new ListView();
listView.Dock = DockStyle.Fill;
listView.BorderStyle = BorderStyle.None;
listView.FullRowSelect = true;
listView.HeaderStyle = ColumnHeaderStyle.Nonclickable;
listView.MultiSelect = false;
listView.View = View.Details;
listView.Columns.Add("File Name", -2);
listView.Columns.Add("Size", -2);
listView.Columns.Add("Comment", -2);
ZipFile zip = new ZipFile(file.FullName);
Enumeration entryEnum = zip.entries();
while (entryEnum.hasMoreElements())
{
ZipEntry entry = (ZipEntry)entryEnum.nextElement();
if (!entry.isDirectory())
{
listView.Items.Add(new ListViewItem(new string[] {
entry.getName(), entry.getSize().ToString(),
entry.getComment() }));
}
}
zip.close();
Controls.Add(listView);
}
}
}
更多精彩
赞助商链接