-1
Я пытаюсь сохранить и прочитать PDF-файлы в локальной базе данных SQL Server CE. Мне удалось сохранить их как двоичные данные в столбце Image
, но я не знаю, как их прочитать и открыть pdf-файл (исходный формат).C# SQL Server CE двоичное восстановление данных
Вот как я хранила PDF файлы:
try
{
SqlCeConnection con = new SqlCeConnection(@"Data Source = D:\C# Projects\StoreFileSqlCe\StoreFileSqlCe\Test_File_Stotage.sdf");
con.Open();
string filePath = textBox1.Text.ToString();
string filename = Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
string strQuery = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
SqlCeCommand cmd = new SqlCeCommand(strQuery, con);
cmd.Parameters.AddWithValue("@Name", filename);
cmd.Parameters.AddWithValue("@ContentType", "application/vnd.ms-word");
cmd.Parameters.AddWithValue("@Data",bytes);
cmd.ExecuteNonQuery();
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
con.Dispose();
}