不允许文件操作.访问被拒绝 [英] File Operation not permitted. Access is denied

查看:171
本文介绍了不允许文件操作.访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从本地计算机读取.xaml文件时,出现类似不允许进行文件操作"之类的错误.

Silverlight 4中的解决方案是什么?

我使用下面的代码..

I get the error like File Operation is not permitted Access is denied while i am reading the .xaml file from my local machine.

What is the solution in Silverlight 4.

I use the below code..

private void button1_Click(object sender, RoutedEventArgs e)
{

 OpenFileDialog Fd = new OpenFileDialog();
                Fd.ShowDialog();

                Fd.Filter = "xaml|*.xaml";

                string LoadedFileName = Fd.File.Name;
                //Load the file    
                FileStream Fs = new FileStream(@LoadedFileName, FileMode.Open);
                      .
                      .
}

推荐答案

FileStream Fs = FD.OpenFile();

就足够了,但这就足够了只读...

is sufficient, but this would be read-only...

private void button1_Click(object sender, RoutedEventArgs e)
{
     OpenFileDialog FD = new OpenFileDialog();
     FD.Filter = "XAML Files (*.xaml)|*.xaml";
     if(FD.ShowDialog() == DialogResult.OK)
     {       
        string fileName = FD.FileName;
        if (File.Exists(fileName))
        {
            FileStream Fs = new FileStream(fileName, FileMode.Open);
        }
     }
}


这篇关于不允许文件操作.访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆