Open File Dialog in C#

Download
Download is available until [expire_date]
  • Version
  • Download 33
  • File Size 55.02 KB
  • File Count 1
  • Create Date March 4, 2016
  • Last Updated March 4, 2016

Open File Dialog in C#

Open File Dialog in C#

Sample code in c# that will let you get the details of the selected file such as the file path, filename, file size and the file extension

Source code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)

            {
                
                long getfilesize =  new System.IO.FileInfo(openFileDialog1.FileName).Length;
                TextBox3.Text =  getfilesize + " (bytes)";
                TextBox1.Text = openFileDialog1.FileName;
                TextBox2.Text = openFileDialog1.SafeFileName;
                textBox4.Text =  System.IO.Path.GetExtension(openFileDialog1.FileName);
            }
        }
    }
}
, , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.