c# - Saving images on the server's file system -
i got code should me save image servers file system:
if (fileupload1.hasfile) { string imgname = fileupload1.filename; fileupload1.saveas(server.mappath("~").tostring() + "\\" + imgname); stream imgstream = fileupload1.postedfile.inputstream; bitmap bmthumb = new bitmap(imgstream); system.drawing.image im = bmthumb.getthumbnailimage(100, 100, null, intptr.zero); im.save(server.mappath("~").tostring() + "\\thumbnail_" + imgname); }
i dont know why convert image thumbnail.. need image saved files system , retreived small image (for avatar)..
i save filename nvarchar(50) in database.
my question how retrieve image filesystem. (i can path database, is: server.mappath("~").tostring() + "\\thumbnail_" + imgname
is need do:
imagecontrol1.imageurl=server.mappath("~").tostring() + "\\thumbnail_" + imgname;
will image appear in imagecontrol or not.
can criticize code , add it..cause first time try save , retrieve filesystem.
will process work on visual studio 2010 local server?
server.mappath
provides absolute path image on server. in order serve image client need relative path. may try using resolveurl method:
imagecontrol1.imageurl = resolveurl("~/thumbnail_" + imgname);
or if remember correctly image control , don't need explicitly call resolveurl
, following might work:
imagecontrol1.imageurl = "~/thumbnail_" + imgname;
Comments
Post a Comment