Retrieve pdf files from sql

Retrieve pdf files from sql

  • 611 Views
  • Last Post 2 weeks ago
  • Topic Is Solved
Stylus STYLUS posted this 3 weeks ago

Insert into

byte[] filedata = null;
MemoryStream ms = new MemoryStream();
filedata = ms.GetBuffer();
axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());
querySaveStaff.Parameters.AddWithValue("@pdf_file", SqlDbType.VarBinary).Value = filedata;

I need to retrieve PDF files from sql database

I try this

try
{
     if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
     {
         byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
         MemoryStream ms = new MemoryStream(ap);
         axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());
         //axAcroPDF1.LoadFile(ms);
     }
     else
     {
         axAcroPDF1.src = null;
     }
}
catch
{
     axAcroPDF1.src = null;
}
Order By: Standard | Newest | Votes
lucy posted this 3 weeks ago

To read pdf file from stream in c#. I think you should save pdf to file, then read it. Exactly what we are going to do is convert from a byte array to a pdf file.

byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
MemoryStream ms = new MemoryStream(ap);
ms.Position = 0;
File.WriteAllBytes(@"D:\mypdf.pdf", ms.ToArray());
Process.Start(@"D:\mypdf.pdf");

You can't read pdf directly from memory stream, but you can read it from file. I hope so you can solve your problem

Stylus STYLUS posted this 3 weeks ago

c# windows form application

lucy posted this 3 weeks ago

I think you should use databinding to retrieve the current row from your DataGridView. I've created a PdfFile table, then use the Entity Framework to save and fetch data from PdfFile table.

CREATE TABLE [dbo].[PdfFile](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Pdf] [image] NULL,
 CONSTRAINT [PK_PdfFile] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Add code to handle read and write your pdf file

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UIDesign
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog() { Filter = "PDF|*.pdf" };
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = File.OpenRead(ofd.FileName);
                MemoryStream ms = new MemoryStream();
                fs.CopyTo(ms);
                DbEntities db = new DbEntities();
                db.PdfFiles.Add(new PdfFile() { Pdf = ms.ToArray() });
                db.SaveChanges();
                MessageBox.Show("OK");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DbEntities db = new DbEntities();
            PdfFile pdf = db.PdfFiles.FirstOrDefault();
            MemoryStream ms = new MemoryStream(pdf.Pdf);
            ms.Position = 0;
            File.WriteAllBytes(@"D:\testpdf.pdf", ms.ToArray());
            Process.Start(@"D:\testpdf.pdf");
        }
    }
}
  • Liked by
  • Stylus STYLUS
Stylus STYLUS posted this 3 weeks ago

I try now. 10 minutes

  • Liked by
  • lucy
Stylus STYLUS posted this 3 weeks ago

Solved. Working. Thank you. Just litle help. I want to open pdf in axAcroPDF1   in windows form

lucy posted this 3 weeks ago

Please try

axAcroPDF1.LoadFile(@"D:\testpdf.pdf");
axAcroPDF1.Enabled = true;

Instead use

Process.Start(@"D:\testpdf.pdf");
  • Liked by
  • Stylus STYLUS
Stylus STYLUS posted this 3 weeks ago

Work. Thank you Lucy

Respect

Stylus STYLUS posted this 3 weeks ago

In my app think I have error in INSERT INTO db statement pdf document

Statement work but some is error when  read from db

byte[] filedata = null;
MemoryStream ms = new MemoryStream();
filedata = ms.GetBuffer();
axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());

INSERT into dbo.documents (pdf_file) VALUES(@pdf_file)

querySaveStaff.Parameters.AddWithValue("@pdf_file", SqlDbType.VarBinary).Value = filedata;

Retriieve from db use this

try
{
    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
    {
        byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
        MemoryStream ms = new MemoryStream(ap);
        ms.Position = 0;
        File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
        axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
        axAcroPDF1.Enabled = true;
    }
    else
    {
        axAcroPDF1.src = null;
    }
}
catch
{
    axAcroPDF1.src = null;
}

But I have some error...Not understand

The folowing exception occured in the DataGridView

System.ArgumentException: Parameter not valid. at system.Drawing.Image.FromStream(Stream stream, Boolean validateImageData)

That is short error text. But why Drawing image when I insert PDF in database and I wan to retrieve pdf in axAcroPDF1

lucy posted this 3 weeks ago

You should add a bindingsource to the DataGridView, then remove the pdf data column. You got the error because you added the pdf_file column to your DataGridView. Your DataGridView tries to convert binary to image, but the current data is a pdf file, so the application has thrown the error.

Stylus STYLUS posted this 3 weeks ago

c# winforms

Stylus STYLUS posted this 3 weeks ago

I remove pdf file column from datagrid, documenstbindingsource   have....

I use data  DocumentsDataGridView_SelectionChanged

if (documentsDataGridView.SelectedRows.Count > 0)
{
    string id = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn1"].Value.ToString();
    string number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value.ToString();
    string count_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn3"].Value.ToString();
    string label = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn4"].Value.ToString();
    string partner = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn5"].Value.ToString();
    string tax_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn6"].Value.ToString();
    string file_location = documentsDataGridView.SelectedRows[0].Cells["file_location"].Value.ToString();
    idTextBox.Text = id;
    numberTextBox.Text = number;
    count_numberTextBox.Text = count_number;
    labelTextBox.Text = label;
    partnerComboBox.Text = partner;
    tax_numberTextBox.Text = tax_number;
    dateDateTimePicker.Value = Convert.ToDateTime(documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn7"].Value);
    file_locationTextBox.Text = file_location;
}

and for pdf this

I think error is here...i dont se pdf focument in axAcroPDF1 when click on datagrid row

try
{
    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
    {
        byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
        MemoryStream ms = new MemoryStream(ap);
        ms.Position = 0;
        File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
        axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
        axAcroPDF1.Enabled = true;
    }
    else
    {
        axAcroPDF1.src = null;
    }
}
catch
{
    axAcroPDF1.src = null;
}

some help please

lucy posted this 3 weeks ago

Have you removed the pdf column?

Stylus STYLUS posted this 3 weeks ago

c# winforms

Stylus STYLUS posted this 3 weeks ago

Removed from datagrid

Stylus STYLUS posted this 3 weeks ago

Sql statement

c# sql database

Stylus STYLUS posted this 3 weeks ago

Sql values in table documents

sql database

lucy posted this 3 weeks ago

Do not add any binary columns in your DataGridView

Stylus STYLUS posted this 3 weeks ago

No. Just look. On pictures last column pdf_file is binary and I remove it in datagrid.

Insert statement work ok...just when want to click on row I need to see that pdf in axAcroPDF1 and use this code

private void DocumentsDataGridView_SelectionChanged(object sender, EventArgs e)
{
    if (documentsDataGridView.SelectedRows.Count > 0)
    {
        string id = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn1"].Value.ToString();
        string number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value.ToString();
        string count_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn3"].Value.ToString();
        string label = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn4"].Value.ToString();
        string partner = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn5"].Value.ToString();
        string tax_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn6"].Value.ToString();
        string file_location = documentsDataGridView.SelectedRows[0].Cells["file_location"].Value.ToString();
        //string pdf_file = documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value.ToString();

        idTextBox.Text = id;
        numberTextBox.Text = number;
        count_numberTextBox.Text = count_number;
        labelTextBox.Text = label;
        partnerComboBox.Text = partner;
        tax_numberTextBox.Text = tax_number;
        dateDateTimePicker.Value = Convert.ToDateTime(documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn7"].Value);
        file_locationTextBox.Text = file_location;
        //axAcroPDF1.src = pdf_file;

        try
        {
            if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
            {

                byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
                MemoryStream ms = new MemoryStream(ap);
                ms.Position = 0;
                File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
                axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
                axAcroPDF1.Enabled = true;
            }
            else
            {
                axAcroPDF1.src = null;
            }
        }
        catch
        {
            axAcroPDF1.src = null;
        }
    }
}
lucy posted this 3 weeks ago

Create a class to map you document table, then add a databinding to document class, remove pdf_file column

Document doc = documentbindingSource.Current as Document;
if(doc != null)
{
    MemoryStream  ms = new MemoryStream(doc.PdfFile);
}

Don't save the pdf file into your database, you should save pdf file name. You should copy pdf file to a share network folder when saving your data.

Stylus STYLUS posted this 3 weeks ago

pdf_column removed.

Create class pdf_show and inside class

Document doc = documentbindingSource.Current as Document;
if(doc != null)
{
    MemoryStream  ms = new MemoryStream(doc.PdfFile);
}

Is that ok?

lucy posted this 3 weeks ago

public class Document
{
    int Id {get; set;}
    int Number {get; set }
    //etc
}

Read data from sql server, then map to the Document class

Stylus STYLUS posted this 3 weeks ago

visual c#

lucy posted this 3 weeks ago

You can use Dapper ORM to fetch data from your database

See How to use Dapper ORM in C#

or you can use SqlDataReader to map your data return from sql server

List<Document> list = new List<Document>();
SqlConnection connection = new SqlConnection(ConnectionString));
connection.Open();
SqlCommand cmd = new SqlCommand("select *from documents", cn)
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
    reader.Read();
    Document obj = new Document();
    doc.Id = reader["id"].ToString();
    doc.Number = reader["number"].ToString();
    //etc
    list.Add(doc);
}
documentBindingSource.DataSource = list;
Stylus STYLUS posted this 3 weeks ago

Datareader

Slow...soryy..

Where to put this

Document doc = documentbindingSource.Current as Document;
if(doc != null)
{
    MemoryStream  ms = new MemoryStream(doc.PdfFile);
}

And where to put this

List<Document> list = new List<Document>();
SqlConnection connection = new SqlConnection(ConnectionString));
connection.Open();
SqlCommand cmd = new SqlCommand("select *from documents", cn)
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
    reader.Read();
    Document obj = new Document();
    doc.Id = reader["id"].ToString();
    doc.Number = reader["number"].ToString();
    //etc
    list.Add(doc);
}
documentBindingSource.DataSource = list;
lucy posted this 3 weeks ago

List<Document> list = new List<Document>();
//etc
//put in Form_Load event handler

and

Document doc = documentbindingSource.Current as Document;
//etc
//put in DocumentsDataGridView_SelectionChanged event handler
Stylus STYLUS posted this 3 weeks ago

Two errors and 1 question.

This we need or not now? in selection changed

//try
//{
//    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
//    {
//        byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
//        MemoryStream ms = new MemoryStream(ap);
//        ms.Position = 0;
//        File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
//        //Process.Start(@"C:\PDFs.pdf");
//        axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
//        axAcroPDF1.Enabled = true;
//    }
//    else
//    {
//        axAcroPDF1.src = null;
//    }
//}
//catch
//{
//    axAcroPDF1.src = null;
//}

Error 1: 

Document doc = documentsBindingSource.Current as Document;
if (doc != null)
{
    MemoryStream ms = new MemoryStream(doc.PdfFile);
}

No have definition for PdfFile

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1061    'Document' does not contain a definition for 'PdfFile' and no extension method 'PdfFile' accepting a first argument of type 'Document' could be found (are you missing a using directive or an assembly reference?)

Error 2

No have definition for doc

reader.Read();
Document obj = new Document();
doc.Id = reader["id"].ToString();
doc.Number = reader["number"].ToString();
//etc
list.Add(doc);

 

Stylus STYLUS posted this 2 weeks ago

In Form load put this code

List<Document_Class> list = new List<Document_Class>();
SqlConnection connection = new SqlConnection(cs);
connection.Open();
SqlCommand cmd = new SqlCommand("select * from documents", connection);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
    reader.Read();
    Document_Class doc = new Document_Class();
    doc.id = reader["id"].ToString();
    doc.number = reader["number"].ToString();
    doc.count_number = reader["count_number"].ToString();
    doc.label = reader["label"].ToString();
    doc.partner = reader["partner"].ToString();
    doc.tax_number = reader["tax_number"].ToString();
    doc.date = reader["date"].ToString();
    doc.file_number = reader["file_number"].ToString();
    doc.pdf_file = reader["pdf_file"].ToString();

    list.Add(doc);
}
documentsBindingSource.DataSource = list;

It is ok but Severity Code   

Description    Project    File    Line    Suppression State
Error    CS0122    'Document_Class.number' is inaccessible due to its protection level for all doc.count_number

doc.label..

etc

Stylus STYLUS posted this 2 weeks ago

I am put in clas...   public class Document_class

but new error is when in clas put

public int id { get; set; }

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0029    Cannot implicitly convert type 'string' to 'int'

admin posted this 2 weeks ago

Change

doc.id = reader["id"].ToString();

to

doc.id = Convert.ToInt32(reader["id"].ToString());
  • Liked by
  • Stylus STYLUS
Stylus STYLUS posted this 2 weeks ago

That change no have error in code. When start app  

Name Value Type ▶ $exception {"Input string was not in a correct format."} System.FormatException

jack posted this 2 weeks ago

Please set debugging for your code to know where the error occurred

Stylus STYLUS posted this 2 weeks ago

private void Documenti(object Formhijo)
{
    if (this.panel3.Controls.Count > 0)
        this.panel3.Controls.RemoveAt(0);
    Form fh = Formhijo as Form;
    fh.TopLevel = false;
    fh.Dock = DockStyle.Fill;
    this.panel3.Controls.Add(fh);
    this.panel3.Tag = fh;
    fh.Show();      ////////////////////here is error...
}


private void Dokumentibutton_Click(object sender, EventArgs e)
{
    Documenti(new Documents());
}

Need to start form in form have class

public class Document_Class
{
    public int id { get; set; }

    public int number { get; set; }

    public int count_number { get; set; }

    public int label { get; set; }

    public int partner { get; set; }

    public int tax_number { get; set; }

    public int date { get; set; }

    public int file_location { get; set; }

    public int pdf_file { get; set; }
}

When want to start file_location have error...

Because  in form load have

List<Document_Class> list = new List<Document_Class>();
SqlConnection connection = new SqlConnection(cs);
connection.Open();
SqlCommand cmd = new SqlCommand("select * from documents", connection);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
     reader.Read();
     Document_Class doc = new Document_Class();
     doc.id = Convert.ToInt32(reader["id"].ToString());
     doc.number = Convert.ToInt32(reader["number"].ToString());
     doc.count_number = Convert.ToInt32(reader["count_number"].ToString());
     doc.label = Convert.ToInt32(reader["label"].ToString());
     doc.partner = Convert.ToInt32(reader["partner"].ToString());
     doc.tax_number = Convert.ToInt32(reader["tax_number"].ToString());
     doc.date = Convert.ToInt32(reader["date"].ToString());
     doc.file_location = Convert.ToInt32(reader["file_location"].ToString());
     doc.pdf_file = Convert.ToInt32(reader["pdf_file"].ToString());
     list.Add(doc);
}
documentsBindingSource.DataSource = list;
jack posted this 2 weeks ago

I think you should check the data type of the fields between your document class and your document table, ensuring that it is correct

Stylus STYLUS posted this 2 weeks ago

What to change in class? I write column type from sql

public class Document_Class
{
    public int id { get; set; }    // int

    public int number { get; set; }   // int

    public int count_number { get; set; } //varchar(255)

    public int label { get; set; }  //varchar(255)

    public int partner { get; set; } //varchar(255)

    public int tax_number { get; set; } //varchar(255)

    public int date { get; set; }  //date

    public int file_location { get; set; }  //varchar(255)

    public int pdf_file { get; set; }  //varbinary(MAX)
}
lucy posted this 2 weeks ago

You should change as shown belown

public class Document_Class
{
    public int id { get; set; }    // int
    public int number { get; set; }   // int
    public string count_number { get; set; } //varchar(255)
    public string label { get; set; }  //varchar(255)
    public string partner { get; set; } //varchar(255)
    public string tax_number { get; set; } //varchar(255)
    public DateTime date { get; set; }  //date
    public string file_location { get; set; }  //varchar(255)
    public byte[] pdf_file { get; set; }  //varbinary(MAX)
}
  • Liked by
  • Stylus STYLUS
Stylus STYLUS posted this 2 weeks ago

Now must repair and another place

List<Document_Class> list = new List<Document_Class>();
SqlConnection connection = new SqlConnection(cs);
connection.Open();
SqlCommand cmd = new SqlCommand("select * from documents", connection);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
     reader.Read();
     Document_Class doc = new Document_Class();
     doc.id = Convert.ToInt32(reader["id"].ToString());
     doc.number = Convert.ToInt32(reader["number"].ToString());
     doc.count_number = reader["count_number"].ToString();
     doc.label = reader["label"].ToString();
     doc.partner = reader["partner"].ToString();
     doc.tax_number = reader["tax_number"].ToString();
     doc.date = reader["date"].ToString(); ////////////////////////////here
     doc.file_location = reader["file_location"].ToString();
     doc.pdf_file = reader["pdf_file"].ToString();//////////////////////here
     list.Add(doc);
}
documentsBindingSource.DataSource = list;
lucy posted this 2 weeks ago

Modify your code as below

doc.date = (DateTime)reader["date"];
or
doc.date = Convert.ToDateTime(reader["date"].ToString());
doc.pdf_file = (byte[])reader["pdf_file"];
  • Liked by
  • Stylus STYLUS
Stylus STYLUS posted this 2 weeks ago

Ok. Class solved.

I need to put this in  datagriview_selection changed (lucy wite that)

Document_Class doc = documentbindingSource.Current as Document_Class;
                 if (doc != null)
                 {
                     MemoryStream ms = new MemoryStream(doc.PdfFile);
                 }

No have definition for PdfFile

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1061    'Document' does not contain a definition for 'PdfFile' and no extension method 'PdfFile' accepting a first argument of type 'Document' could be found (are you missing a using directive or an assembly reference?)

Question 2

Did we need this in selection changed or not?

try
                {
                    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)

                    {                        

                        byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
                        MemoryStream ms = new MemoryStream(ap);
                        ms.Position = 0;
                        File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
                        //Process.Start(@"C:\PDFs.pdf");
                        axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
                        axAcroPDF1.Enabled = true;


                    }
                    else
                    {
                        axAcroPDF1.src = null;
                    }
                }
                catch
                {
                    axAcroPDF1.src = null;
                }

This is complete code for selection changed

private void DocumentsDataGridView_SelectionChanged(object sender, EventArgs e)
        {
            if (documentsDataGridView.SelectedRows.Count > 0)
            {
                string id = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn1"].Value.ToString();
                string number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value.ToString();
                string count_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn3"].Value.ToString();
                string label = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn4"].Value.ToString();
                string partner = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn5"].Value.ToString();
                string tax_number = documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn6"].Value.ToString();
                string file_location = documentsDataGridView.SelectedRows[0].Cells["file_location"].Value.ToString();
                //string pdf_file = documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value.ToString();

                idTextBox.Text = id;
                numberTextBox.Text = number;
                count_numberTextBox.Text = count_number;
                labelTextBox.Text = label;
                partnerComboBox.Text = partner;
                tax_numberTextBox.Text = tax_number;
                dateDateTimePicker.Value = Convert.ToDateTime(documentsDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn7"].Value);
                file_locationTextBox.Text = file_location;
                //axAcroPDF1.src = pdf_file;

                Document_Class doc = documentbindingSource.Current as Document_Class;
                 if (doc != null)
                 {
                     MemoryStream ms = new MemoryStream(doc.PdfFile);
                 }

                try
                {
                    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)

                    {                    


                        byte[] ap = (byte[])(documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value);
                        MemoryStream ms = new MemoryStream(ap);
                        ms.Position = 0;
                        File.WriteAllBytes(@"C:\PDFs.pdf", ms.ToArray());
                        //Process.Start(@"C:\PDFs.pdf");
                        axAcroPDF1.LoadFile(@"C:\PDFs.pdf");
                        axAcroPDF1.Enabled = true;

                    }
                    else
                    {
                        axAcroPDF1.src = null;
                    }
                }
                catch
                {
                    axAcroPDF1.src = null;
                }


            }
        }
Stylus STYLUS posted this 2 weeks ago

Some help?

Close