开发者

Problem with retrieveing file upload control

I saved fileupload control in session. But when I am retrieving in another page(ie to know whether it has file 开发者_StackOverflow社区or not),it is showing error as "object instances not set to an object". Where can be the fault? The code I used to get that fileupload control is

{
   Fileupload myupload=(Fileupload)Session["Fileupload1"];
   if(myupload.HasFile)
    {
          //some code
    }
}


Well that's not going to work. You can't put controls in session state. You'll need to process the file upload on the page that received the post. Then you'll need to save off the file to a temporary directory or something on the server.

I'd go back to the drawing board and try another approach.


Without seeing the actual stack trace, it looks like Session["Fileupload1"] is null.


I would say that if you are saving the fileUpload to session, it's maybe not the best way to tackle your given problem, of which we know little about.

That said, you should check to see if an object is in session before casting it as something in case it has been lost.

if (Session["MySessionVar"] != null)
{
      <type> myVar = (<type>)Session["MySessionVar"]; 
}
else
{
      // set default/write warning to log/warn user
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜