Error in this line
binaryvalue = HttpContext.Current.Session["excel"];
Cannot implicitly convert type 'object' to 'System.Data.Linq.Binary'. An explicit conversion exists (are you missing a cast?)
protected void lnkadd_Click(object sender, EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadMethod));
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
Binary binaryvalue;
int returnvalue;
GridViewRow gvrow = ((Control)sender).Parent.Parent as GridViewRow;
int rowindex = gvrow.RowIndex;
Label lblsNo = (Label)gv.Rows[rowindex].Cells[0].FindControl("lblsNo");
string _ino = "";
_ino = lblsNo.Text;
binaryvalue = HttpContext.Current.Session["excel"];
returnvalue = _dc.update_storedprocedure(_ino, binaryvalue);
}
public static Binary tobinary(string str)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public static void ThreadMethod()
{
System.Windows.Forms.OpenFileDialog openfile = new System.Windows.Forms.OpenFileDialog();
openfile.ShowDialog();
string pathname = Path.GetFileName(openfile.FileName);
Binary excelfile;
string _fileextension = Path.GetExtension(pathname);
Binary binaryvalue = null;
if (_fileextension == ".xlsx" | _fileextension == ".xls")
{
//excelfile = pathname;
binaryvalue = tobinary(pathname);
if (binaryvalue != null)
{
HttpContext.Current.Session["excel"] = binaryvalue;
}
}
}