asp.net - how to upload multiple images using single fileuploader button in 4.0 -


hi coder have fileupload button used insert images system , save them database want select multiple images using single file uploader in framework 4.0

each images has priority well

code:

protected void btnsubmit_click(object sender, eventargs e) {     try     {                                             boolean enable = true;         string relativepath = "https://images/module/" + ddlppt.selectedvalue + "/";         //get imagename fileupload control         string imgname = fileuploadimages.filename.tostring();         //sets image path if exist store image in place else create new 1         string imgpath = "images/modules/" + "" + ddlppt.selectedvalue + "/";         bool isexists = system.io.directory.exists(server.mappath(imgpath));         if (!isexists)             system.io.directory.createdirectory(server.mappath(imgpath));         //then save folder         fileuploadimages.saveas(server.mappath(imgpath + imgname));         //open database connection         con.open();         //query insert * images_master database         sqlcommand cmd = new sqlcommand("insert image_master(userid,image_name,description,moduleid,pptid,priority,imageurl,relativepath,isenable,dt) values('"+session["trainer"]+"','" + imgname + "','" + tbdescription.text + "','" + ddlmodule.selectedvalue + "','" + ddlppt.selectedvalue + "','" + lblpriority.text + "',@imageurl,'" + relativepath + "','" + enable + "','" + datetime.now + "')", con);         //passing parameters query         cmd.parameters.addwithvalue("@image_name", imgname);         cmd.parameters.addwithvalue("@description", tbdescription.text.trim());         cmd.parameters.addwithvalue("@moduleid", ddlmodule.selectedvalue);         cmd.parameters.addwithvalue("@pptid", ddlppt.selectedvalue);         cmd.parameters.addwithvalue("@priority", lblpriority.text);         cmd.parameters.addwithvalue("@imageurl", imgpath + imgname);         cmd.parameters.addwithvalue("@relativepath", relativepath);         cmd.executenonquery();                    tbdescription.text = "";         logs.insertlogs(session["role"].tostring() + ":" + session["trainer"].tostring(), "createmodule.aspx.cs btn_click", "query executed insert image");         response.write("<script>alert('image uploaded..!!!');</script>");                 }     catch (exception ex2)     {      }         {         if (con.state == connectionstate.open)         {             con.close();         }     } } 

in select file using file upload button , click on btnsubmit save image details in database want select multiple images using upload button , on click on btnsubmit data save in database in advance !!!!

try this

 string[] files = directory.getfiles(server.mappath(imgpath));            list<string> filenames = new list<string>();     (int = 0; < files.length; i++)     {  try     {                                             boolean enable = true;         string relativepath = "https://images/module/" + ddlppt.selectedvalue + "/";         //get imagename fileupload control         string imgname = fileuploadimages.filename.tostring();         //sets image path if exist store image in place else create new 1         string imgpath = "images/modules/" + "" + ddlppt.selectedvalue + "/";         bool isexists = system.io.directory.exists(server.mappath(imgpath));         if (!isexists)             system.io.directory.createdirectory(server.mappath(imgpath));         //then save folder         fileuploadimages.saveas(server.mappath(imgpath + path.getfilename(files[i])));         //open database connection         con.open();         //query insert * images_master database         sqlcommand cmd = new sqlcommand("insert image_master(userid,image_name,description,moduleid,pptid,priority,imageurl,relativepath,isenable,dt) values('"+session["trainer"]+"','" + path.getfilename(files[i]) + "','" + tbdescription.text + "','" + ddlmodule.selectedvalue + "','" + ddlppt.selectedvalue + "','" + lblpriority.text + "',@imageurl,'" + relativepath + "','" + enable + "','" + datetime.now + "')", con);         //passing parameters query         cmd.parameters.addwithvalue("@image_name", path.getfilename(files[i]));         cmd.parameters.addwithvalue("@description", tbdescription.text.trim());         cmd.parameters.addwithvalue("@moduleid", ddlmodule.selectedvalue);         cmd.parameters.addwithvalue("@pptid", ddlppt.selectedvalue);         cmd.parameters.addwithvalue("@priority", lblpriority.text);         cmd.parameters.addwithvalue("@imageurl", imgpath + path.getfilename(files[i]));         cmd.parameters.addwithvalue("@relativepath", relativepath);         cmd.executenonquery();                    tbdescription.text = "";         logs.insertlogs(session["role"].tostring() + ":" + session["trainer"].tostring(), "createmodule.aspx.cs btn_click", "query executed insert image");         response.write("<script>alert('image uploaded..!!!');</script>");                 }     catch (exception ex2)     {      }         {         if (con.state == connectionstate.open)         {             con.close();         }     } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -