using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Diagnostics
{
class Program
{
static void Main(string[] args)
{
string filename = null;
using (SaveFileDialog sFile = new SaveFileDialog())
{
sFile.Filter = "Text (Tab delimited)(*.txt)|*.txt|CSV (Comma separated)(*.csv)|*.csv";
if (sFile.ShowDialog() == DialogResult.OK)
{
filename = sFile.FileName;
WriteRegKey(diagnostic, filename);
}
}
}
}
}
I am getting an error:
The type or namespace name ‘SaveFileDialog’ could not be found (are you missing a using directive or an assembly reference?)
I did try adding the System.Windows.Forms namespace, but I was not able to.
You have to add a reference to the
System.Windows.Formsassembly.Also, you must add the
STAThreadattribute to your application entry point method.But honestly, that’s a terrible idea. A console application shouldn’t have any other UI that the console itself. As the namespace of
SaveFileDialogsuggests,SaveFileDialogshould be used forFormsonly.