How to Use OpenFile Dialog and Copy that Path

Step 1: Form

Drag down a button and write its text as "Open".



Step 2: Code

Double click on the button and write this code.
 
 
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

 

namespace First_Csharp_app

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Button1_click(object sender, EventArgs e)

        {

            OpenFileDialog openfile = new OpenFileDialog();

            if (openfile.ShowDialog() == System.Window.Forms.DialogResult.OK)

            {

                string strfilename = openfile.FileName;

                MessageBox.show(strfilename);

            }

        }

    }

 

Step 3: Output

Now run your application.
 


To learn more, you can go to my blog_munesh.