c# - Uploading multiple photos to folder and their paths to database through a single click -
i having problem making logic uploading 3 image @ same time database , paths database. using 3 textboxes images titles, 3 file upload buttons , submit button.
here have tried far:
protected void button1_click1(object sender, eventargs e) { using (property_dbdatacontext context = new property_dbdatacontext()) { property_image image = new property_image(); image.prop_id = "1"; image.image_title = _imagetitle1.text; image.image_title = _imagetitle2.text; image.image_title = _imagetitle3.text; string imagename = _pictureupload1.filename.tostring(); string imagepath = "wp-content/uploads/2013/05/" + imagename; _pictureupload1.saveas(server.mappath(imagepath)); image.image_url = imagepath.tostring(); context.property_images.insertonsubmit(image); context.submitchanges(); } }
the interface:
the fileuploader names are: _pictureuploader1, _pictureuploader2, _pictureuploader3 textboxes names are: _imagetitle1, _imagetitle2, _imagetitle3 button name: button1
i not getting whether loop utilize or not utilize loop @ all.
i want store record in different rows this:
prop_id | image_title | image_url 1 | auto | wp-content/uploads/2013/05/car.jpg 1 | bus | wp-content/uploads/2013/05/bus.jpg 1 | truck | wp-content/uploads/2013/05/truck.jpg
with limited knowledge of class construction / database construction :
you want 1-many relationship in database, accomplish need modify next code :
property_image image = new property_image(); image.prop_id = "1"; image.image_title = _imagetitle1.text; image.image_title = _imagetitle2.text; image.image_title = _imagetitle3.text; string imagename = _pictureupload1.filename.tostring(); string imagepath = "wp-content/uploads/2013/05/" + imagename; _pictureupload1.saveas(server.mappath(imagepath)); image.image_url = imagepath.tostring();
to :
property_image image = new property_image(); image.prop_id = "1"; image.images.add(new propimage() { title = _imagetitle1.text, url = _pictureupload1.filename.tostring() }); image.images.add(new propimage() { title = _imagetitle2.text, url = _pictureupload2.filename.tostring() }); image.images.add(new propimage() { title = _imagetitle3.text, url = _pictureupload3.filename.tostring() });
and alter property_image class next :
class property_image { public string prop_id {get; set;} public list<propimage> images { get; set; } }
and add together propimage class :
class propimage { public string title {get; set;} public string url {get; set;} }
because want 1-many relationship, need have 1-many relationship in class structure, i.e. id can have multiple images (title + url), need create list of image objects within class
c# asp.net image file-upload
No comments:
Post a Comment