Object reference not set to an instance of an object

Posted by Mahendra under C# on 4/26/2010 | Views : 17093 | Status : [Member] | Replies : 4
if(filUplTemp.PostedFile.FileName != null)

it giving me following error

"Object reference not set to an instance of an object."




Responses

Posted by: Vuyiswamb on: 4/26/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Are you sure that the name of the Filupload control is filUplTemp can we see the markup declaration of the control.

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Naveenmanam on: 4/27/2010 [Member] Starter

Up
0
Down
use :

System.IO.DirectoryInfo dirInfo

dirInfo = New System.IO.DirectoryInfo("C:\");


NaveenKumar

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

Posted by: Kunal2383 on: 4/27/2010 [Member] Starter

Up
0
Down
Hi Mahendra,

In your code
filUplTemp.PostedFile
is coming as NULL and hence the exception.
First check
filUplTemp.PostedFile
for NULL and then use
.FileName
.

One suggestion:
I think, your FileName is string. So, instead of checking it for NULL use: string.IsNullOrEmpty(...)

Thanks & Regards,
Kunal Chowdhury | http://www.kunal-chowdhury.com | http://twitter.com/kunal2383

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

Posted by: Pavanandey on: 4/28/2010 [Member] Bronze

Up
0
Down


Check wheter ur fileupload control is in updatepanel , since fileupload control does not work in updatepanel

Thanks
Pavan Kumar
Mark Answer if this fits the need

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

Login to post response