OK, I followed the Microsoft MSDN and copied their code exactly, and it work for RTF files only, but I want to be able to open text files, html files, php files....basically any files.
The code is:
Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { } public void LoadMyFile() { // Create an OpenFileDialog to request a file to open. OpenFileDialog openFile1 = new OpenFileDialog(); // Initialize the OpenFileDialog to look for RTF files. openFile1.Filter = "Text Files|*.txt"; // Determine whether the user selected a file from the OpenFileDialog. if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && openFile1.FileName.Length > 0) { // Load the contents of the file into the RichTextBox. richTextBox1.LoadFile(openFile1.FileName); } } private void openmenu1_Click(object sender, EventArgs e) { LoadMyFile(); } } }
I get this error when I double click on the file to open:
"File Format is not valid", and it relates to this code:
.Code:richTextBox1.LoadFile(openFile1.FileName);
I am a beginner in C#, and want to understand how it works,
Thanks,
BP



LinkBack URL
About LinkBacks



