Ok, so I just started teaching myself C# today, and I have finally gotten completely stuck. I am trying the use a browse option to select a file. The file path will then be displayed in textBox1. Then I need what is textBox1 to be loaded by clicking the Launch button.
I currently have textBox1.Text set as the location of the file. When I type \TestList.xml into the textbox, it goes through fine and does what it is supposed to. Any other time however, like if I typed c:\TestList.xml or c:\TestList.xml it just says that it cant use the textBox1.Text format as a file location. Any idea how to fix this? here is the code. I added a bunch of dashes next to the line that is causing the problem. Thank you very much for any help with this.
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;
using System.Xml;
namespace Combined
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Corner Open File Dialog";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
XmlDataDocument xmldata = new XmlDataDocument();
// causing problem
xmldata.DataSet.ReadXml(Application.StartupPath + textBox1.Text);
dataGridView1.DataSource = xmldata.DataSet;
dataGridView1.DataMember = "Unit";
}
}
}