如何从数据库中读取pdf,doc等文件 [英] how to read pdf,doc,etc file from database

查看:211
本文介绍了如何从数据库中读取pdf,doc等文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...



将pdf文件名存储到文件夹中并将文件url存入数据库。

现在如何阅读(检索)那个文件来自数据库?我只被打到这里。



请帮助我。

解决方案

在你的menthod中使用此代码: br $>


  string  strFilePath =  @  \ .Files\test.pdf; 
Response.ContentType = jpg / doc / pdf;
Response.AddHeader( Content-Disposition attachment; filename = \ + strFilePath + \ );
Response.TransmitFile(Server.MapPath(strFilePath));
Response.End();





注意:strFilePath是虚拟路径。

服务器.MapPath()将使用指定的虚拟路径返回物理路径。


嗨......



谢谢你的帮助重播。

我也找到它的解决方案。

按钮事件:

con = new MySqlConnection(cs);

cmd = new MySqlCommand(select * from files,con);

da = new MySqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);



string path = Server.MapPath(〜/ PDF /+ ds.Tables [0] .Rows [0] [FileName]。ToString());

WebClient客户端=新的WebClient();

Byte [] buffer = client.DownloadData(path);



if(buffer!= null)

{

Response.ContentType =application / pdf;

Response.AddHeader(content- length,buffer.Length.ToString());

Response.BinaryWrite(buffer);

}

谢谢你。

Hi...

am stored pdf file name into folder and file url into database.
now how read(retrieving) that file from database? am struck here only.

pls help me.

解决方案

Use this code in your menthod:

string strFilePath = @"\Files\test.pdf";
                Response.ContentType = "jpg/doc/pdf";
                Response.AddHeader("Content-Disposition", "attachment;filename=\"" + strFilePath + "\"");
                Response.TransmitFile(Server.MapPath(strFilePath));
                Response.End();



Note: strFilePath is the virtual path.
Server.MapPath() will return the physical path using your specified virtual path.


Hi...

thank u for ur replay.
am also find the solution to it like.
in button event:
con = new MySqlConnection(cs);
cmd = new MySqlCommand("select * from files", con);
da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

string path = Server.MapPath("~/PDF/" + ds.Tables[0].Rows[0]["FileName"].ToString());
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);

if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
thank u.


这篇关于如何从数据库中读取pdf,doc等文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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