Thursday, 2 March 2017
On 21:37 by Vardan Kumar in C# No comments
How to give save path through browse button c#
For an application to be user friendly, it is necessary to provide maximum accessibility features. Since our application should follow abstraction and should focus on hiding complexities to user, so a good GUI(Graphical user interface) with accessibility features will show your hard work while building the application. No matter how much you burn midnight oil while developing back-end of your application, if it lacks a good GUI with accessibility features it is definitely in vain.
If your application generates a file, which user is supposed to read or gather information then giving privilege of choosing the save path for the file to user is always nice. Button control is the best way to do this.
Logic
- Firstly we'll create a button click event.
private void btn_Browse_Click_1(object sender, EventArgs e)
2. Now we'll create an instance of SaveFileDIalog.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
3.Now we'll set the filter for our save file dialog that is what kind of file user should be prompted to save which is shown under save as type drop down. Multiple filters are separated by vertical bar.
saveFileDialog1.Filter = "Excel|*.xlsx";
4.Now we'll give title to our dialog box.
saveFileDialog1.Title = "Save Excel report";
5.Now we'll call ShowDialog method and if method return value seems correct then we'll assign the path to our desired label, off course we want to store the file path selected by user to use it further. If you don't want to display the path selected by user you can also use a string identifier to store the path.
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
lbl_Path.Text = saveFileDialog1.FileName;
Note: Don't forget to change other characteristics of label if any after changing its text such as tool tip etc.
Path Before clicking browse button |
Save File Dialog Box |
Save Path after selecting path |
Source Code
private void btn_Browse_Click_1(object sender, EventArgs e)
{
//Instance creation
SaveFileDialog saveFileDialog_csp = new SaveFileDialog();
// Seting filter
saveFileDialog_csp.Filter = "Excel|*.xlsx";
// Giving title
saveFileDialog_csp.Title = "Save Excel report";
// show dialog box
if (saveFileDialog_csp.ShowDialog() == DialogResult.OK)
// Storing the path
lbl_Path.Text = saveFileDialog_csp.FileName;
// Changing tool tip
tt.SetToolTip(lbl_Path, lbl_Path.Text);
// Making label visible
lbl_Path.Visible = true;
}
Subscribe to:
Post Comments (Atom)
Search
Popular Posts
-
Troubleshooting Cisco VPN client Before starting troubleshooting, Let us see what VPN is and what it requires to perform its intended f...
-
Evolution-Mobile Phones With the development of portable technology,wireless communication has so evolved that (According to the announce...
-
File Versioning C# File versioning, saving file with unique file name in c# File versioning allows a user to have several versions of ...
-
Text Box Hint in c# Windows Form Application Text Box Hint in c# Windows Form Application While developing a windows form applicat...
-
Unable to set the Freeze Panes property of Window Class C# It is generally easy to resolve the compile time errors because the reason fo...
0 comments:
Post a Comment