[CommandMethod("fod")]
public void testOpenFileDial()
{
string filename = "";
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Drawing777"; // Default file name
dlg.DefaultExt = ".dwg"; // Default file extension
dlg.Filter = "Drawing (.dwg)|*.dwg"; // Filter files by extension
dlg.InitialDirectory = @"C:\Test";// Default finitial folder extension
dlg.RestoreDirectory = true;
dlg.Multiselect = false;//true
dlg.ValidateNames = true;
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
filename = dlg.FileName;
}
System.Windows.MessageBox.Show(filename);
}
For WPF based app better use this method (see MSDN)
Code - C#: [Select]
[CommandMethod("fod")] public void testOpenFileDial() { string filename = string.Empty; // Configure open file dialog box { FileName = "Drawing777", DefaultExt = ".dwg", Filter = "Drawing (.dwg)|*.dwg", InitialDirectory = @"C:\Test", RestoreDirectory = true, Multiselect = false, ValidateNames = true }; // Show open file dialog box bool? result = dlg.ShowDialog(); // Process open file dialog box results if (result) { // Open document filename = dlg.FileName; } System.Windows.MessageBox.Show(filename); }
For WPF based app better use this method (see MSDN)
Code: [Select][CommandMethod("fod")]
public void testOpenFileDial()
{
string filename = "";
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Drawing777"; // Default file name
dlg.DefaultExt = ".dwg"; // Default file extension
dlg.Filter = "Drawing (.dwg)|*.dwg"; // Filter files by extension
dlg.InitialDirectory = @"C:\Test";// Default finitial folder extension
dlg.RestoreDirectory = true;
dlg.Multiselect = false;//true
dlg.ValidateNames = true;
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
filename = dlg.FileName;
}
System.Windows.MessageBox.Show(filename);
}