Opening FileTable Files in c# / .net 4

一笑奈何 提交于 2019-12-10 18:33:46

问题


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

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

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)

Grateful for any advice.


回答1:


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");

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);
}

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";


来源:https://stackoverflow.com/questions/13970617/opening-filetable-files-in-c-sharp-net-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!