打开文件对话框,多选=true,我无法访问文件
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);
}
}
问题是我想在 Silverlight 中打开多个文件,除了将文件名传递到 foreach 循环之外,我不知道有任何其他方法可以做到这一点。问题是 Silverlight 不喜欢我尝试循环访问文件,它必须是来自用户的直接命令。 在这种情况下它会抛出异常:
不允许进行文件操作
那么是否有另一种方法来操作本地文件(不是从隔离空间),或者有什么方法可以使该代码工作? 谢谢你们。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用 file.FullName 打开文件。您获得一个 FileInfo 对象,使用其 OpenXxxx() 方法之一打开该文件。
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.