c# - Image saving into database from a folder and get back into the UI -
i have field in app (c#) save image database. written following code save image folder , save path database. image not getting saved folder.
string imgname = fileupload1.filename.tostring(); string imgpath = null; if (imgname == "") { //int taxiid = convert.toint32(hiddenfield1.value); taxi t = null; t = taxi.owner_getbyid(tx.taxi_id, usm.orgid); imgpath = t.carimage; } else { imgpath = "imagestorage/" + imgname; } fileupload1.saveas(server.mappath(imgpath)); tx.carimage = imgpath;
i think problem add name path try , me works fine if save this:
fileupload1.saveas(server.mappath("imagestorage") + imgname);
and @rahul mentioned add try catch prevent errors.
and check
if (imgname == "")
according understanding it's not posible imgname "" anyway better add check if fileupload has file.
if (fileuploadcontrol.hasfile)