0
My question is the continuation of this question: Link to the other question
I managed to transform my file into bytes and insert it into a table in SQL Server, but now I want it from inside an application I am doing in C# I want to open this file. That is to do reverse engineering (byte > open file).
The code used for insertion:
Anexo a = new Anexo();
FileStream fs = new FileStream(a.Caminho, FileMode.Open, FileAccess.Read);
a.Arquivo = new byte[fs.Length];
fs.Read(a.Arquivo, 0, System.Convert.ToInt32(fs.Length));
string SQL = @"INSERT INTO ANEXO (NOME, CAMINHO, ARQUIVO) VALUES (@nome, @caminho, @arquivo)";
Cmd = new SqlCommand(SQL, Con);
Cmd.Parameters.Add("@nome", SqlDbType.VarChar).Value = a.NomeArquivo;
Cmd.Parameters.Add("@caminho", SqlDbType.VarChar).Value = a.Caminho;
Cmd.Parameters.Add("@arquivo", SqlDbType.VarBinary).Value = a.Arquivo;
Cmd.ExecuteNonQuery();
Windows form or Web?
– PauloHDSousa
C# Windows Forms
– Lucas Vasconcelos
What file format? you know? PDF, IMAGE, . TXT, will display where?
– PauloHDSousa
The format is . msg are Outlook emails. Thanks for the replies Paul
– Lucas Vasconcelos
You will take from the bank and save on the computer, correct?
– PauloHDSousa
No. It is already in the database... there in my application I have a gridview... and each tuple of this grid will have an attachment of an email in a column with button to open this attachment. Ai at this time comes the byte pass part to the file and dps open.
– Lucas Vasconcelos
Have you solved it yet? In this code you posted as answer (it was deleted) here: http://answall.com/questions/43713/como-fa%C3%a7o-para-insert-qualquer-exten%C3%A7%C3%a3o-de-file-in-a-sql-database you can see what is wrong. If you’re interested, put in that code that we explained to you how to solve.
– Caffé