开发者

how can show blob file in mvc page?

I uploaded some different blob type (.pdf, .xls, .gif. .png ...) in databas开发者_高级运维e. now I want to show its icon (by type) and read its blob content in my view page, for example if this is a pdf file show pdf icon and by double clicking on that file open

please help me, thank you


What you want to do consists of two parts: a view page that displays a link (with the icon) for each file and a separate action (in one of your controllers) that delivers the actual file contents.

The easiest approach is probably if you analyze the file type when you upload the files into the database and then store the file type in a separate column in the database. For most files, you can derive the file type from the first few bytes of the files (see Magic Number).

The action of the controller responsible for delivering the file content to the user is straightforward to implement. Based on some ID of the file, it loads it from the database into a byte array and returns it as a FileContentResult instance.

To create a link to the file (in your view page), just use Html.ActionLink or a similar function with the controller name, action name and the ID of the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜