Quote:
quote:Originally posted by rodmcleay
I am new to C# also but I think you need to use the datatype "Stream".
Stream imgStream = UploadFile.PostedFile.InputStream;
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
I'm running into the same type of problem but I do have my code with the Stream in it.
I'm getting a System.NullReferenceException: Object reference not set to an instance of an object.
I'd put all my code here but you guys would probably die trying to read it all. I did use the reference link to get my code (
http://www.developerfusion.com/show/3905/5/) and even though I used that code I'm still getting the error.
Here's my click function (and yes my item is named BtnUpload not UploadBtn
any suggestions??
public void BtnUpload_Click(object sender, EventArgs e)
{
if (Page.IsValid) //Save Image
{
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string imgContentType = UploadFile.PostedFile.ContentType;
string imgName = txtAdCode.Value;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);
int RowsAffected = SaveToDB(imgName, imgBinaryData, imgContentType);
if (RowsAffected > 0)
{
Response.Write("<br />Image Saved<br />");
}
else
{
Response.Write("<br />An error has occurred, please upload again<br />");
}
}
}