Skip to content

PDF File Problem

sreeni2219

Asked Oct 28, 2005, 6:29 AM EDT1 answer
Share
LinkedInX

I have stored my PDF files in the database as binary code.
Now i want to retriee the the binay format file and want to display to my user.
But when ever i have tried the file is not visible. Why? Any help..
Your help highly appriciated!I have written below code..

Basically i want to show the report to the user, I like to store in memory rather physically storing the report in hard drive.
Or do we have any better way to display the report to my user from database (But constraint is File should show in PDF format only!)

 

Java
   string strString= "Select Image From ImageTable where ID=1"
   SqlConnection connection = new SqlConnection(connectionstring);
    connection.Open();
   SqlDataAdapter da = new SqlDataAdapter(strSpName, connection);
    da.SelectCommand.CommandType = CommandType.Text;

    DataSet ds = new DataSet();

    // Fill dataset
    da.Fill(ds,"Image");

    if (ds.Tables[0].Rows.Count > 0)
    {

     byte[] Myimage= new byte[0];
     DataRow dr;
     dr=ds.Tables["Image"].Rows[0];
     Myimage =  (byte[])dr["NoticeImage"];
     int ArraySize = new int();
     ArraySize = Myimage.GetUpperBound(0);
     FileStream fs = new FileStream(@"C:\Temp\image.pdf", FileMode.OpenOrCreate, FileAccess.Write);
     fs.Write(Myimage, 0,ArraySize);
     fs.Flush();
     fs.Close();
     File.Open(@"C:\Temp\image.pdf", FileMode.Open);


    }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    I am not sure if you can simply convert a stream to PFD direct.
    0