file upload probel is occour in my code

Posted by Mona.Agr1186 under ASP.NET on 4/3/2013 | Points: 10 | Views : 523 | Status : [Member] | Replies : 3
when we upload file then we got that error
"Object reference not set to an instance of an object."
and we are using that code for file upload

String picname8 = System.IO.Path.GetFileName(fileup_procat_att.PostedFile.FileName);
String picext8;
int namelength8;
namelength8 = picname8.Length;
int index8 = picname8.IndexOf(".");
int sub_length8 = namelength8 - index8;

namelength8 = picname8.Length;
picext8 = picname8.Substring(index8, sub_length8);
saveLocation8 = "product catalog" + "/" + procatatt + picext8;
fileup_procat_att.PostedFile.SaveAs(MapPath(saveLocation8));




Responses

Posted by: Jayakumars on: 4/3/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
chek ur upload file size.

Mark as Answer if its helpful to you

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

Posted by: aswinialuri-19361 on: 4/3/2013 [Member] Starter | Points: 25

Up
0
Down
hi
Try this i think it will help you

if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentType == "image/jpeg" || FileUpload1.PostedFile.ContentType == "image/gif" || FileUpload1.PostedFile.ContentType == "image/x-png" && FileUpload1.PostedFile.ContentLength == 1024)
{
string path = "~/Images/" + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath(path));


Image3.ImageUrl = "~/Images/" + FileUpload1.FileName;
Image3.Visible = true;


Thanks & Regards
Aswini Aluri


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

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

Posted by: Jenniffer on: 4/3/2013 [Member] Starter | Points: 25

Up
0
Down
static string photoPath = HttpContext.Current.Server.MapPath(".");

In Button Click:

string FileUp = Txt_FileUpload.FileName;
Session["Images"] = FileUp;
try
{
if (Txt_FileUpload.HasFile)
{
Txt_FileUpload.SaveAs(MapPath("~/ImageFolder/" + Txt_FileUpload.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/ImageFolder/") + Txt_FileUpload.FileName);
imname = @"\ImageFolder\" + "_" + FileUp;
Images = imname.ToString();
}

}
catch (Exception ex)
{
}

Mark as Answer if its helpful to you...


Thanks & Regards
JENI

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

Login to post response