打开文件的FileTable在C#/。NET 4 [英] Opening FileTable Files in c# / .net 4

查看:300
本文介绍了打开文件的FileTable在C#/。NET 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含许多不同的文件类型一的FileTable(.DOC,.PDF,.xls的等等)。

I have a Filetable containing many different document types (.doc;.pdf;.xls etc).

我写一个小的网络(C#/。NET 4)搜索应用程序。搜索使用全文索引用的FileTable找到内容的伟大工程。

I am writing a small web (C# / .net 4) search app. Search works great using fulltext index with filetable to find content.

但我努力寻找我的应用程序的方式有搜索结果作为可以启动有关的文档链接?而就在处理不同的文件类型? (假设客户端已经安装了Word /土坯/ EXCEL等)

But I'm struggling to find a way in my app to have the search results as links which can launch the document in question? And just handle the different file types? (Assume client has Word/adobe/excel installed etc)

感谢您的任何建议。

推荐答案

您将需要编写一个自定义页面处理程序以适当的HTTP标头流字节到客户端。您将需要决定是否支持在线观看(在浏览器中打开 - 内容处置:内联 的)与使用附件(外部观看例如内容处置:附件 的)。

You will need to write a custom page handler to stream the bytes to the client with the proper HTTP headers. You will need to decide whether to support inline viewing (open in the browser - Content-Disposition: inline) versus external viewing using an attachment (e.g. Content-Disposition: attachment).

Response.AddHeader("Content-Disposition", "attachment; filename=example.pdf");

如果您使用的是ASP.NET MVC - 您可以利用的 FileResult 来简化这一过程,但创建自己的处理程序将不会太大不同。

If you are using ASP.NET MVC - you can leverage the FileResult to streamline this process, but creating your own handler wouldn't be too much different.

public FileResult Download()
{
    byte[] fileBytes = ...; // from FileTable
    string fileName = "example.txt";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

要处理各种MIME类型(PDF,DOC,XLS)最好的方法是静态定义支持的文件类型或动态阅读IIS 并指定相应的内容类型 HTTP标头。

The best approach to handling various MIME types (PDF, DOC, XLS) is to statically define the supported file types or dynamically read IIS and assign the appropriate Content-Type HTTP header.

Response.ContentType = "application/pdf";

这篇关于打开文件的FileTable在C#/。NET 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆