I want to check if my file does exist first, but if not.. How can i make it exist?
if (File.Exists(Filepath))
{
// if it does exist, itll show datas as data grid view
dataGridView2.DataSource = ds.Tables[0].DefaultView;
}
else
{
// if it doesnt exist, how can i make it exist? or create an XML file
}
Use StreamWriter to create a new file, specify the path.
You can do this:
You could use
XmlDocument
andXmlTextWriter
You could also just use a
FileStream
with theFile
class.Another approach by using LINQ to XML types without explicit using of writers