Hi All,
Here the requirement.
A user can attach multiple files(may be.doc, .pdf whatever), then the file has to be stored in the database when he clicks a submit button. these files( the content of the file) which the user attaches has to be displayed in the data grid view. I am able to get one file attached and viewed in the data grid view, but because the sql table has unique ID column it is able to store and retrieve only one file. I know I have to create a secondary table to implement the multiple attachment logic, but cannot get the connectivity and the code for it.
What I have tried:
// Open file to read using file path
FileStream FS = new FileStream(textBox1.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Add filestream to binary reader
BinaryReader BR= new BinaryReader(FS);
// get total byte length of the file
long allbytes = new FileInfo(textBox1.Text).Length;
// read entire file into buffer
FileBytes = BR.ReadBytes((Int32)allbytes);
// close all instances
FS.Close();
FS.Dispose();
BR.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error during File Read " + ex.ToString());
}