En iyi yanıtlayıcılar
c# sqlserver da kayıtlı pdf dosyasını açma

Soru
-
pdf dosyasını veritabnına eklıyorum.. aşagıdakı kodlamayla veritabanındakı pdf dosyasını belirtilen adrese kaydediyor. pdf dosyasını aç butonuna basınca direkt veritabanından açmasını istiyorum nasıl yapabilirim...
buradakı kodla sadece local diske kaydediyor..benım istedigim butona tıklayınca direkt açılsın.. teşekkürler.
SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=rapor;Integrated Security=True");
connection.Open();
// Select binary data from db
SqlCommand command = new
SqlCommand("select veri from rapor where ID=1", connection);
byte[] buffer = (byte[])command.ExecuteScalar();
connection.Close();
// storing file to C drive
FileStream fs = new FileStream(@"D:\test.pdf", FileMode.Create);
fs.Write(buffer, 0, buffer.Length);
fs.Close();
od
Yanıtlar
-
Windows uygulamasında görüntülenecekse;
void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=rapor;Integrated Security=True");
connection.Open();
// Select binary data from db
SqlCommand command = new SqlCommand("select veri from rapor where ID=1", connection);
byte[] buffer = (byte[])command.ExecuteScalar();
connection.Close();
PDFViewer PDFViewer1;
PDFViewer1.LoadDocument(buffer);
}
PDFViewer indirmek ve incelemek için;
http://www.gnostice.com/docs/pdfone_dot_net/Gnostice_PDFOne_Windows_PDFViewer_PDFViewer_LoadDocument@byte[].html
- Yanıt Olarak İşaretleyen osman06 12 Nisan 2017 Çarşamba 14:28
Tüm Yanıtlar
-
Bu bir web sayfasında görüntülenecekse;
protected void Page_Load(object sender, EventArgs e)
{
Context.Response.Buffer = false;
SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=rapor;Integrated Security=True");
connection.Open();
// Select binary data from db
SqlCommand command = new SqlCommand("select veri from rapor where ID=1", connection);
byte[] buffer = (byte[])command.ExecuteScalar();
connection.Close();
if (Context.Response.IsClientConnected)
{
Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
Context.Response.Flush();
}
}
-
-
Windows uygulamasında görüntülenecekse;
void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=rapor;Integrated Security=True");
connection.Open();
// Select binary data from db
SqlCommand command = new SqlCommand("select veri from rapor where ID=1", connection);
byte[] buffer = (byte[])command.ExecuteScalar();
connection.Close();
PDFViewer PDFViewer1;
PDFViewer1.LoadDocument(buffer);
}
PDFViewer indirmek ve incelemek için;
http://www.gnostice.com/docs/pdfone_dot_net/Gnostice_PDFOne_Windows_PDFViewer_PDFViewer_LoadDocument@byte[].html
- Yanıt Olarak İşaretleyen osman06 12 Nisan 2017 Çarşamba 14:28