Dealy

Dealy

  • NA
  • 213
  • 0

Object reference not set to an instance of an object (byte[]

Aug 2 2016 1:36 AM
Hello,
I have the following code:
  1. public byte[] getFile(FileUpload file)  
  2.     {  
  3.         byte[] bytes=null;  
  4.   
  5.         using (Stream fs = file.PostedFile.InputStream)  
  6.         {  
  7.             using (BinaryReader br = new BinaryReader(fs))  
  8.             {  
  9.                 bytes = br.ReadBytes((Int32)fs.Length);  
  10.             }  
  11.         }  
  12.         return bytes;  
  13.     }  
 When I compile the procedure I get the following error message: "Object reference not set to an instance of an object."
 
Any idea how to fix the error?
 
Thank you in advance. 

Answers (8)