I've some trouble to upload file from Memory Stream to database (it's visible in DB as 0x so i guess it doesn't get saved properly). I am not sure whether it's a problem with Stream being created or save to db from stream should be done differently.
private void test {
byte[] storage = new byte[500000];
using (MemoryStream stream = new MemoryStream(storage))
DocX documentWord = DocX.Create(stream);
// some stuff
documentWord.Save();
databaseFilePut(stream);
}
public static void databaseFilePut(MemoryStream stream) {
byte[] file;
using (var reader = new BinaryReader(stream)) {
file = reader.ReadBytes((int) stream.Length);
// reader.Close();
}
//stream.Close();
//}
using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetailsDZP))
using (var sqlWrite = new SqlCommand("INSERT INTO Raporty (RaportPlik) Values(@File)", varConnection)) {
sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;
sqlWrite.ExecuteNonQuery();
}
}
What am i doing wrong? I am using Docx codeplex library.