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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started