First check to see if the FotoFile is not null
Attaching some code that i use to upload files
HttpFileCollection myFiles = Request.Files;
CodePlayDB myCode = new CodePlayDB();
if(myFiles.Count != 0)
{
try
{
HttpPostedFile myFile = myFiles[0];
if( myFile != null)
{
if(myFile.FileName != "")
{
try
{
int fileLength = myFile.ContentLength;
byte[] fileData = new byte[fileLength];
Stream myStream = myFile.InputStream;
myStream.Read(fileData, 0, fileLength);
string fileContentType = myFile.ContentType;
myCode.AddImageToDB(fileContentType, fileData);
}
catch (Exception ex1)
{
Label1.Text = "Error uploading file '" + myFile.FileName +
"'<br>Error: " + ex1.ToString();
}
}
}
}
catch (Exception ex)
{
Label1.Text = "Error uploading file '" +
fileUpload1.PostedFile.FileName + "'<br>Error: " + ex.ToString();
}
}
else
Label1.Text = "Please enter a valid file";
}
--
Regards,
HD
"Ola Myrgart" <pb****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi!
This is the errorcode I get when I try to insert some new data inot my
SQL DB.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Line 125: Dim connectionString As String =
"server='localhost'; user id='sa'; password='xxxxx'; Database='xxxxx'"
Line 126: Dim ImageStream As Stream =
FotoFile.PostedFile.InputStream
Line 127: Dim byteData(FotoFile.PostedFile.ContentLength) As
Byte
The problem is on Line 126.
What´s the problem? Can´t find it out myself.
Is there anyone who has any ideas ?
OM "Myggan"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!