Hello everybody!
I want to save images in Paint.Net to my SQL database in image-fields. The problem I get is that the byte stream is not a valid image when I get it back from the database.
The SaveForm and TransferPictures are classes I have implemented myself and they work fine. The problem can be the SaveToStream method I use in the Document class.
Does anyone have an idea?
The code is:
private void menuFileSave_Click(object sender, System.EventArgs e)
{
SaveForm sf = new SaveForm();
sf.ShowDialog();
string fileName = sf.getFilename();
Stream stream = null;
stream = (Stream)new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
stream = workspace.Document.SaveToStream1(stream, null);
stream.Position = 0;
byte[] fileByte = new byte[stream.Length];
int offset = 0;
int remaining = fileByte.Length;
stream.Read(fileByte, offset, remaining);
TransferPictures trans = new TransferPictures();
trans.uploadFileToDatabase(fileByte, fileName);
}
Thanks!