c# - FileUpload in FormView -
c# - FileUpload in FormView -
i have problem regarding add together image url within database.i'm using fileupload method within formview in asp.net.and have table called duyurular can record image url.btw,i'm using sql server database. question is;i'm doing process update,delete , create proclamation in formview.i can upload images within folder called "img" fileupload. however,i want record within database well.when add together within database infos,there no image url. finally,i can't add together image url within database.
here code;
public partial class panel_yoneticipaneli : system.web.ui.page { fileupload dosya, dosya1; //textbox t1, t2, t3; //button btn; sqlconnection con; static string str = "data source=sert;initial catalog=mmakina;integrated security=true"; string yol = ""; protected void page_load(object sender, eventargs e) { dosya = (fileupload)formview2.findcontrol("fileupload1"); dosya1 = (fileupload)formview2.findcontrol("fileupload2"); // btn = (button)formview2.findcontrol("resimkaydetbutonu"); //t1 = (textbox)formview2.findcontrol("duyurubasliktextbox"); //t2 = (textbox)formview2.findcontrol("duyuruiceriktextbox"); //t3 = (textbox)formview2.findcontrol("duyurutarihitextbox"); label1.visible = false; if (session["kullaniciid"]!=null) { con = new sqlconnection(str); sqlcommand sorgu = new sqlcommand("select * kullanici kullaniciadi=@kullaniciadi", con); sorgu.parameters.add("@kullaniciadi", sqldbtype.varchar).value = session["kullaniciadi"]; con.open(); sqldatareader oku = sorgu.executereader(commandbehavior.closeconnection); label1.visible = true; while (oku.read()) { label1.text = oku["kullaniciadi"].tostring(); } } else { response.redirect("error.aspx"); } } protected void button1_click(object sender, eventargs e) { formsauthentication.signout(); roles.deletecookie(); session.clear(); response.redirect("giris.aspx"); } protected void btn_click(object sender,eventargs e) { seek { if (dosya.hasfile) { dosya.saveas(server.mappath("~/img/") + dosya.filename); system.drawing.image resim = system.drawing.image.fromfile(server.mappath("~/img/") + dosya.filename); yol = "img/" + dosya.filename; resim.dispose(); dbupload(); } } grab (exception ex) { } } public void dbupload() { seek { sqlconnection sc = new sqlconnection("data source=sert;initial catalog=mmakina;integrated security=true"); sqlcommand scom = new sqlcommand("insert duyuru(duyururesmi) values(@duyururesmi)", sc); scom.parameters.addwithvalue("@duyururesmi", dosya.filename); scom.executenonquery(); sc.close(); }catch(exception p){ p.message.tostring(); } } protected void updatebutton_click(object sender, eventargs e) { seek { if (dosya.hasfile) { dosya.saveas(server.mappath("~/img/") + dosya.filename); yol = "img/" + dosya.filename; response.write("fileupload çalışıyor..."); dbupload(); } } grab (exception ex) { } }
thanks in advance comments can share.
i suggest upload image name without specifying total url, , can save image base of operations path in web.config '<add key="imagesbasepath" value="/img" />'
can alter path have images , can command view of image concatenating image name configurationmanager.appsettings["imagesbasepath"]
better.
c# .net asp.net file-upload formview
Comments
Post a Comment