2
I have an xls file that I upload and transform into binary as follows:
FileStream fs = new FileStream(physicalPath + "/cadastros/documentos/" + "AWS-Estudantes_" + Convert.ToString(System.DateTime.Now.Year) + "-" + Convert.ToString(System.DateTime.Now.Month) + "-" + Convert.ToString(System.DateTime.Now.Day) + ".xls", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
_planilha = br.ReadBytes((Int32)fs.Length);
fs.Close();
br.Close();
Then I call my method to record in the bank passing the file name and the _planilha
that is byte[] _planilha
:
string binary = string.Empty;
for (int i = 0; i < _planilha.Length; i++)
{
binary += _planilha[i];
}
Here I take the data from inside the _planilha
:
providerFactory.ClearParameters();
providerFactory.SqlStat.Append("INSERT INTO BinaryFiles(Titulo,Arquivo) VALUES ('" + _fileName + "', CAST(CAST('" + binary + "' AS VARCHAR(MAX)) AS BINARY(8000))) ");
And here I make the recording, on the bench my field is a binary(8000)
but it turns out that it turns the binary I created from the xls into a binary. But I only need to record what I passed to it. That it’s not happening because without the Cast(Cast
he of conversion error.
Vc uses varbinary(8000) in the bank?
– Marco Aurelio
Last time I had to write the entire file - pdf - I couldn’t do a direct SQL, I had to use a feature of the q framework I have to add a parameter; this feature allows me to add n parameters; I passed the file as vector of bytes. Another difference is that I used varbinary(MAX) in the bank.
– Marco Aurelio
Use Binary(8000) in the bank and Marco, that’s what I did there, _spreadsheet is a byte[] that saves the bytes of all text, so I read all indices and concateno for Inary, and then Inary has a line with all bytes of the file and it’s what I write in the bank... But he does not accept to record like this in a Inary or varbinary
– Leonardo Dutra