Problem while uploading the files to database with fileUploadeder1_FileReceived event

Jan 13, 2011 at 5:14 AM

I am using Filereceived event to save the files in byte array form in Viewstate.

Following is the code:

When i upload multiple images ViewState["ImageTable"] is always null. I dont know whats the problem it should not be null during uploading of images after first image is uploaded.

 protected void PropertImageDataTable()
    {

        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("PropertyImage", typeof(byte[])));

        ViewState["ImageTable"] = dt;

    }



 protected void fileUploadeder1_FileReceived(object sender, com.flajaxian.FileReceivedEventArgs e)
    {

 if (ViewState["ImageTable"] == null)
        {
            PropertImageDataTable();
        }

        SqlParameter[] Param = new SqlParameter[1];

        Int32 intImageLength = e.File.ContentLength;
        byte[] logo = new byte[intImageLength];
        Stream objStream;
        objStream = e.File.InputStream;
        objStream.Read(logo, 0, intImageLength);


        DataTable imageTable;// = new DataTable();
        imageTable = (DataTable)ViewState["ImageTable"];

        DataRow dr = imageTable.NewRow();
        dr["PropertyImage"] = logo;

        imageTable.Rows.Add(dr);
        ViewState["ImageTable"] = imageTable;
}