c# - Tried save as image to project folder, but error to find a path -


i have asp application save image project folder , save path mysql db, if try code,

"could not find part of path 'c:\users\tree\documents\visual studio 2012\projects\ecommerce_hp\ecommerce_hp\foto\" 

here code

if (f1.postedfile == null || f2.postedfile == null || f3.postedfile == null)         {             lbleror.text = "silahkan pilih foto, minimal 1 foto";         }         else         {             try             {                 string f1, f2, f3;                 f1 = path.getfilename(f1.postedfile.filename);                 f2 = path.getfilename(f2.postedfile.filename);                 f3 = path.getfilename(f3.postedfile.filename);                  f1.saveas(server.mappath("foto/"+f1));                 f2.saveas(server.mappath("foto/"+f2));                 f3.saveas(server.mappath("foto/"+f3));                  con.open();                 mysqlcommand cmd = new mysqlcommand("insert databarang(merkid,namabarang,stokbarang,harga,tanggalbarangmasuk,imgpath1,imgpath2,imgpath3) values(@a,@b,@c,@d,@e,@f,@g,@h)", con);                 cmd.parameters.addwithvalue("@a",ddlmerk.selectedvalue);                 cmd.parameters.addwithvalue("@b",txtnama.value.trim());                 cmd.parameters.addwithvalue("@c",txtstok.value.trim());                 cmd.parameters.addwithvalue("@d",txtharga.value.trim());                 cmd.parameters.addwithvalue("@e",system.datetime.now);                 if(f1!=null)                 {                     cmd.parameters.addwithvalue("@f","foto/"+f1);                 }                 else                 {                     cmd.parameters.addwithvalue("@f",null);                 }                  if(f2!=null)                 {                     cmd.parameters.addwithvalue("@g","foto/"+f2);                 }                 else                 {                     cmd.parameters.addwithvalue("@g",null);                 }                  if(f3!=null)                 {                     cmd.parameters.addwithvalue("@h","foto/"+f3);                 }                 else                 {                     cmd.parameters.addwithvalue("@h",null);                 }                 cmd.executenonquery();                 con.close();                 reset();             }             catch (exception ex)             {                 con.close();                 lbleror.text = ex.message.tostring();                 errm.visible = true;             }         } 

when try change

f1.saveas(server.mappath("foto/"+f1));   f1.saveas(server.mappath("~/foto/"+f1)); 

the result same, not find part of path... solution ?

my project structure

my project structure

your foto folder inside admin folder. use

f1.saveas(server.mappath("~/admin/foto/"+f1)); 

instead of

f1.saveas(server.mappath("~/foto/"+f1)); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -