I want to pop up a dialog for the user to open a file. How do I do this?

asked 01 Jun '10, 21:45

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%


First, you need to import a reference to the File Dialog Service:

[Import(SoapBox.Core.Services.FileDialog.FileDialogService, 
        typeof(IFileDialogService))]
private Lazy<IFileDialogService> fileDialogService { get; set; }

Then you can use that service to get a file name from an Open File Dialog:

private Dictionary<string, string> filters 
    = new Dictionary<string, string>();

filters.Add("txt", "Text Files");

bool addExtension = true;
bool checkFileExists = true;
bool checkPathExists = true;

string fileName = fileDialogService.Value.OpenFileDialog(
        "txt", @"c:\", filters,
        "My Open File Dialog Title",
        addExtension, checkFileExists, checkPathExists);
if(fileName != null)
{
    // do something
}
link

answered 01 Jun '10, 21:45

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×23
×2
×1

Asked: 01 Jun '10, 21:45

Seen: 2,025 times

Last updated: 01 Jun '10, 21:45

powered by OSQA