Hi programmers, welcome to new article of c# windows application. This article i’ll write program to Get File Name and File Path in Textbox in C# Windows Application.
We can achieve the output OpenFileDialog class , v1 object calls Filter Property to filter file types. v1 call ShowDialog method. when v1.ShowDialog method equals to OK then
condition true. v1 call filename and stored into textbox and file path store into richtextbox. Let’s see the codes.

Double click on Open Button Control and write below codes.

Directly use below codes into editor.
using System;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog v1 = new OpenFileDialog();
v1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
if (v1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = v1.FileName;
richTextBox1.Text = Path.GetFileName(v1.FileName);
}
}
}
}
Happy coding…thanks.