Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#显示oracle数据库中的pdf文件(pdf路径存储在数据库中)?_C#_Asp.net_Oracle_Pdf_Handler - Fatal编程技术网

使用C#显示oracle数据库中的pdf文件(pdf路径存储在数据库中)?

使用C#显示oracle数据库中的pdf文件(pdf路径存储在数据库中)?,c#,asp.net,oracle,pdf,handler,C#,Asp.net,Oracle,Pdf,Handler,C#代码: Pdfhandler.ashx代码: HyperLink1.NavigateUrl = "Pdfhandler.ashx?empid=" + TextBox8.Text; 当我运行代码时,我可以通过输入员工代码来显示一名员工的pdf,但如果我在文本框中输入另一名员工代码,则不会显示特定员工的pdf。有人能帮你解决这个问题吗?你可以试试这样的方法 { MemoryStream memoryStream = new MemoryStream(); s

C#代码:

Pdfhandler.ashx代码:

HyperLink1.NavigateUrl = "Pdfhandler.ashx?empid=" + TextBox8.Text;

当我运行代码时,我可以通过输入员工代码来显示一名员工的pdf,但如果我在文本框中输入另一名员工代码,则不会显示特定员工的pdf。有人能帮你解决这个问题吗?

你可以试试这样的方法

{

        MemoryStream memoryStream = new MemoryStream();

        string sql = "SELECT pdfpath FROM pdfstore WHERE empl_code = " + id + "";

        OracleCommand cmd = new OracleCommand(sql, connection);
        //cmd.Parameters.AddWithValue("@id", id);
        connection.Open();

        OracleDataReader reader = cmd.ExecuteReader();
        reader.Read();
        if (reader.HasRows)
        {
            //byte[] file = Encoding.ASCII.GetBytes("imgpath");
            //byte[] file = Encoding.UTF8.GetBytes("imgpath");
            //Get Image Data
            //byte[] file = (byte[])reader["imgpath"];
            byte[] file = File.ReadAllBytes(reader["pdfpath"].ToString());

            reader.Close();
            connection.Close();
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
            context.Response.BinaryWrite(file);
            memoryStream.Dispose();
        }
        else
        {

        }

如果pdfpath只是一个字符串,为什么要使用ReadAllBytes?那么我应该使用什么呢?memorystream有什么问题吗?我应该清理它吗?如果是,怎么做?因为我可以在一段时间后显示pdf。不清楚pdfpath中是否存储了pdf文件的名称和路径,或者存储了用于重建PDFpdfpath的字节,只是存储了存储pdf的当前路径。非常感谢,工作正常。但是在InternetExplorer中,我需要刷新页面以打开pdf。如何解决此问题?您可以尝试设置
HyperLink1.Target=“\u blank”。这将在新选项卡中打开pdf。那你就不需要刷新了,我已经给你了。但问题仍然存在,在firefox中,它工作得很好。
if (reader.HasRows)
{
    context.Response.Clear();
    context.Response.ContentType = "application/pdf";
    context.Response.TransmitFile(reader["pdfpath"].ToString()); //the path must be actual physical path of the file
    contest.Response.End();
}
else
{
    context.Response.Clear();
    context.Response.ContentType = "text/plain";
    context.Response.Write("No file found");
    contest.Response.End();
}