Search code examples
c#silverlightexceptionopenfiledialog

OpenFile dialog, Multiselect=true, i cannot reach files


private void btnNew_Click(object sender, System.Windows.RoutedEventArgs e)
{        
    OpenFileDialog of = new OpenFileDialog();
    of.Multiselect = true;
    of.Filter = "JPG Dosyaları|*.jpg|JPEG Dosyaları|*.jpeg";
    of.ShowDialog();
    foreach (var file in of.Files)
    {
        MessageBox.Show(file.FullName);
    }
}

The problem is i want to open multiple files' in Silverlight and i don't know any other way doing it than passing the filenames into a foreach loop. The problem is Silverlight don't like if i try to reach files in a loop, it must be a direct command from user. In this case it throws an exception:

File operation not permitted

So is there another way manipulating local files (not from isolated space), or is there any way i can make this code work? Thanks guys.


Solution

  • Don't use file.FullName to open the file. You get a FileInfo object back, use one of its OpenXxxx() methods to open the file.