ramin149
پنج شنبه 15 مهر 1389, 10:54 صبح
سلام من یه فایل آپلود در صفحه دارم که از طریق یا کلاس عکسم رو ذخیره می کنم و وقتی فایل آپلودم داخل یه UpdatePanel باشه وقتی به این خط از کلاسم می رسه
private Label Error = new Label();
private FileUpload fileup2 = new FileUpload();
public photos2(Label lbl , FileUpload up)
{
this.Error = lbl;
this.fileup2 = up;
}
public void upload()
{
string mypath = HttpContext.Current.Server.MapPath(".") + "\\photos\\oldadmin";
string [] validextention = {".jpg", ".png", ".bnp", ".jpeg"};
string x = System.IO.Path.GetExtension(fileup2.PostedFile.Fil eName);
if (Array.IndexOf(validextention, x.ToLower()) < 0)
{
Error.Text="you seleted invalid type of image for uploading";
return;
}
long sizefile = fileup2.PostedFile.ContentLength;
sizefile = sizefile / 1024;
if (sizefile > 200)
{
Error.Text="invalid size image uploading";
return;
}
string filename = System.IO.Path.GetFileName(fileup2.PostedFile.File Name);
//Exists موجود هست یا نیست
while (System.IO.File.Exists(mypath + "\\" + filename))
{
int c = filename.Length - x.Length;
filename = filename.Insert(c, "3");
}
fileup2.PostedFile.SaveAs(mypath + filename);
Error.Text="youfileuploaded";
}
این خطا رو می ده
Object reference not set to an instance of an object.
خواهشا یکی کمکم کنه ؟!
private Label Error = new Label();
private FileUpload fileup2 = new FileUpload();
public photos2(Label lbl , FileUpload up)
{
this.Error = lbl;
this.fileup2 = up;
}
public void upload()
{
string mypath = HttpContext.Current.Server.MapPath(".") + "\\photos\\oldadmin";
string [] validextention = {".jpg", ".png", ".bnp", ".jpeg"};
string x = System.IO.Path.GetExtension(fileup2.PostedFile.Fil eName);
if (Array.IndexOf(validextention, x.ToLower()) < 0)
{
Error.Text="you seleted invalid type of image for uploading";
return;
}
long sizefile = fileup2.PostedFile.ContentLength;
sizefile = sizefile / 1024;
if (sizefile > 200)
{
Error.Text="invalid size image uploading";
return;
}
string filename = System.IO.Path.GetFileName(fileup2.PostedFile.File Name);
//Exists موجود هست یا نیست
while (System.IO.File.Exists(mypath + "\\" + filename))
{
int c = filename.Length - x.Length;
filename = filename.Insert(c, "3");
}
fileup2.PostedFile.SaveAs(mypath + filename);
Error.Text="youfileuploaded";
}
این خطا رو می ده
Object reference not set to an instance of an object.
خواهشا یکی کمکم کنه ؟!