Question: Hello, I am working with visual studio and having trouble reading a text file to the default text editor for that machine. The code below

Hello, I am working with visual studio and having trouble reading a text file to the default text editor for that machine.

The code below is what I have currently. It will get to the right directory but when i click open on the textfile i get the error "An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll" which basically means the system cannot find the file. Could anyone tell me what I am doing wrong please?

private void buttonViewEmp_Click(object sender, EventArgs e) { openFileDialog1.FileName = "testfile"; //input openFileDialog1.Title = "testfile"; openFileDialog1.Filter = "Text Files(*.txt)|*.txt|All files(*.*)|*.*";

if (openFileDialog1.ShowDialog() == DialogResult.OK) { System.Diagnostics.Process.Start(Directory.GetCurrentDirectory() + "*.*"); }

}

I am using these namespaces

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.VisualBasic; using System.IO;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!