How to store session value into binary-error

Posted by Oswaldlily under ASP.NET on 4/30/2013 | Points: 10 | Views : 1110 | Status : [Member] | Replies : 1
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));

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();

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;


Posted by: Jitendrasoft09 on: 4/30/2013 [Member] [MVP] Starter | Points: 25

As you first store your session into string and then convert string into binary, please see below link lhat would be helpful for you.
You can use like that as below code-
byte []arr = System.Text.Encoding.ASCII.GetBytes(str);

Jitendra Kumar
If my post helps you, plz mark as an answer.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response