.net - how to upload file using wpf and c# in windows application -
i have form on there browse button , when clicked it, dialogue box open , selected file path or file name of file show on textbox have written code file path not display in text box, have try resolve fail, kindly me out of this, , there 1 thing more, want upload in specfic folder , download on system , please tell me also
using system; using system.collections.generic; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.shapes; using system.data; using system.data.sqlclient; using system.linq; using system.io; //using system.drawing; using system.componentmodel; namespace ris_2 { /// <summary> /// interaction logic crud.xaml /// </summary> public partial class crud : window { public crud() { this.initializecomponent(); // insert code required on object creation below point. } private void browse_btn_click(object sender, routedeventargs e) { stream checkstream = null; // openfiledialog op1 = new openfiledialog(); microsoft.win32.openfiledialog dlg = new microsoft.win32.openfiledialog(); dlg.multiselect = false; dlg.filter = "all image files | *.*"; //dlg.filter = "(*.pfw)|*.pfw|all files (*.*)|*.*"; nullable<bool> result = dlg.showdialog(); // if ((bool)dlg.showdialog()) if(result==true) { try { if ((checkstream = dlg.openfile()) != null) { // myimage.source = new bitmapimage(new uri(dlg.filename, urikind.absolute)); //listbox1.items.add(openfiledialog.filename); string filename = dlg.filename; tb_file.text = filename; // tb_file.appendtext(dlg.filename.tostring()); messagebox.show("successfully done", filename); } } catch (exception ex) { messagebox.show("error: not read file disk. original error: " + ex.message); } } else { messagebox.show("problem occured, try again later"); } } } }
frankly, me code looks okay, it's strange doesn't work. having said that, i'd suggest take different approach. using wpf, @ data binding. if in code behind define property
private string _filename; public string filename { get{return _filename;} set{ _filename = value; onpropertychanged("filename"); }
the implementation of onpropertychanged , simple explanation of inotifypropertychanged can found @ http://www.java2s.com/tutorial/csharp/0470__windows-presentation-foundation/raisethepropertychangedevent.htm
in xaml, have textblock should extended binding
textblock x:name="tb_file" text="{binding path=filename}"
to ensure binding property in code behind works, please refer binding objects defined in code-behind
hope helps (at least first part of question)
Comments
Post a Comment