Silverlight访问路径被拒绝

时间:2019-02-05 11:51:22

标签: c# silverlight system.io.file

我的代码逐行读取一个文本文件,没有编译错误,但是当我对其进行测试时,它显示出:“拒绝访问路径”

代码:`public void EA()         {

        var lines = File.ReadLines("Status.txt").Skip(81).Take(24).ToList(); //Read txt file line by line
        int timeout = 0;
        int success = 0;
        for (int i = 0; i < 24; i++) //for cicle for each line in txt 
        {


            if (lines[i] == "okay")
            {
                success++; //count for how many okay in txt

            }

            else if (lines[i] == "fail")
            {
                timeout++; //count for how many fail in txt
            }
        }
        if (timeout < 1)
        {
            BitmapImage verde = new BitmapImage(new Uri("/SilverLightTest;component/Estados/Verde.png", UriKind.Relative));
            eaMafra.Source = verde;

        }

        else
        {
            BitmapImage vermelho = new BitmapImage(new Uri("/SilverLightTest;component/Estados/Vermelho.png", UriKind.Relative));
            eaMafra.Source = vermelho;
        }

        if (timeout == 0) //if none, everything is ok
        {
            eaQuantos.Text = "ok";
        }

        else //if any show how many timeouts
        {
            eaQuantos.Text = timeout.ToString();
        }
    }`

错误的详细信息:

  

{System.Security.SecurityException:不允许文件操作。拒绝访问路径“ Status.txt”。      在System.IO.FileSecurityState.EnsureState()      在System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost)      在System.IO.FileStream..ctor处(字符串路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,FileOptions选项,String msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost)      在System.IO.StreamReader..ctor处(字符串路径,编码编码,布尔型detectEncodingFromByteOrderMarks,Int32 bufferSize,布尔值CheckHost)      在System.IO.StreamReader..ctor处(字符串路径,编码编码,布尔型detectEncodingFromByteOrderMarks,Int32 bufferSize)      在System.IO.File.ReadLines(字符串路径)

我试图将“ txt”文件夹共享给“所有人”(修改并阅读),但这并不能解决问题

0 个答案:

没有答案