Displaying a file dialog
You can display a message box or confirmation dialog using the ICommonUI
object. The ICommonUI
object can be obtained from the Window.UI
property of the IApplication
object.
Displaying a file open dialog
You can display a file open dialog using the ShowOpenFileDialog
method of the ICommonUI
object. The return value is the path of the file selected in the dialog, and null is returned if the method is canceled.
public void ShowOpenFileDialog(ICommandContext c, ICommandParams p)
{
var dialogResult = c.App.Window.UI.ShowOpenFileDialog("Open file", "Text files (*.txt)|*.txt|All files (*.*)|*.*");
if (dialogResult != null)
{
c.App.Output.WriteLine("sample", $"Result : {dialogResult} ");
}
else
{
c.App.Output.WriteLine("sample", "Cancelled.");
}
}
Display the file save dialog
The file save dialog can be displayed by using the ShowSaveFileDialog
method of the ICommonUI
object. The return value will be the path of the file selected in the dialog, and null will be returned if the dialog is canceled.
public void ShowSaveFileDialog(ICommandContext c, ICommandParams p)
{
var dialogResult = c.App.Window.UI.ShowSaveFileDialog("Save file", "Text files (*.txt)|*.txt|All files (*.*)|*.*");
if (dialogResult != null)
{
c.App.Output.WriteLine("sample", $"Result : {dialogResult} ");
}
else
{
c.App.Output.WriteLine("sample", "Cancelled.");
}
}
Display the folder selection dialog
You can display the folder opening dialog with the ShowSelectFolderDialog
method of the ICommonUI
object and get the path of the folder selected in the dialog. If the dialog is canceled, it returns null.
public void ShowSelectFolderDialog(ICommandContext c, ICommandParams p)
{
//Get the default folder for the dialog
var defaultFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//Select a folder
var dialogResult = UI.ShowSelectFolderDialog("Select Folder", defaultFolder);
if (dialogResult != null)
{
c.App.Output.WriteLine("sample", $"Result : {dialogResult} ");
}
else
{
c.App.Output.WriteLine("sample", "Cancelled.");
}
}