问题描述
大家好:
现在,我创建一个项目,其类型为``WPF浏览器应用程序''.我没有添加任何其他代码.我只想获取一个完整的文件名,包括其路径.但这会带来一些错误.这可能是由于没有文件许可引起的.所有代码如下.
now, I create a project, its type is "WPF Browser Application". I add no any other code. i just want to get a full file name including its path. but it give some errors. it is probably caused by no permission of file. all the code as follows.
公共部分类MainPage:页面
{
私有字符串FilePath;
public MainPage()
{
public partial class MainPage : Page
{
private string FilePath;
public MainPage()
{
``InitializeComponent();
InitializeComponent();
OpenFileDialog fdlg = new OpenFileDialog(); > fdlg.FilterIndex = 1;
if(fdlg.ShowDialog()== true)
{{ //此行给出错误
}
}
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Filter = "All files (*.*)|*.*|dll files (*.dll)|*.dll";
fdlg.FilterIndex = 1;
if (fdlg.ShowDialog() == true)
{
string FilePath = fdlg.FileName; // this line gives error
}
}
请帮助我.
预先感谢.
推荐答案
运行XBAP应用程序(或任何其他基于浏览器,Intranet或Internet的应用程序)与在完全信任环境中本地运行应用程序完全不同.要从这样的环境中打开文件,您需要使用OpenFileDialog(已完成操作),然后直接从对话框中打开文件.本质上,如果您要替换行
Running XBAP applications (or any other browser, intranet or internet based app) is a very different beast to running applications locally in a full-trust environment. To open a file from such an environment, you need to use an OpenFileDialog (as you have done), but then open the file from the Dialog directly. Essentially, if you were to replace the line
字符串FilePath = fdlg.FileName;
string FilePath = fdlg.FileName;
与
流s = fdlg.Open();
Stream s = fdlg.Open();
,您将获得可以阅读的信息流.如果您确实需要传入的文件名,可能有一种方法可以实现,但不是OpenFileDialog.
you would get a stream you could read. If you really need the file name passed in, there is probably a way to do it, but OpenFileDialog isn't it.
希望这会有所帮助.
这篇关于OpenFileDialog给出错误!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!