简体   繁体   English

未经授权的访问异常不断显示

[英]Unauthorized Access Exception keeps showing

I coded this app in Visual Studio using C#.我使用 C# 在 Visual Studio 中编写了这个应用程序。 In this app, I have to access a binary file from a location using a browse button and choose a saving location after the conversion.在这个应用程序中,我必须使用浏览按钮从某个位置访问一个二进制文件,并在转换后选择一个保存位置。 However, when clicking on the "Start Conversion" button, it keeps showing this UnauthorizedAccessException.但是,当单击“开始转换”按钮时,它一直显示此 UnauthorizedAccessException。 We disabled everything in the computer (firewall etc..) but nothing seems to work.我们禁用了计算机中的所有内容(防火墙等),但似乎没有任何效果。 It keeps showing the exception.它一直显示异常。 Here is the part of the code.这是代码的一部分。

    private void StartConversion1(object sender, RoutedEventArgs e)
    {

        try
        {
            Byte[] a1 = File.ReadAllBytes(filePath1.Text);
            Byte[] a2 = new Byte[(a1.Length) / 2];


            a2[0] = a1[0];
            int i = 2;
            int j = 1;
            while (i < a1.Length)
            {

                a2[j] = a1[i];
                i = i + 2;
                j = j + 1;
            }
            try
            {
                File.WriteAllBytes(savingPath1.Text, a2);
                MessageBox.Show("Conversion Complete");
            }
            catch (UnauthorizedAccessException ex)
            {
                Form3 frm3 = new Form3();
                frm3.Text = "XGIGA formatter";
                frm3.ShowDialog();
            }
        } catch(FileNotFoundException ex)
        {
            string stackTrace = ex.ToString();
            Form1 frm1 = new Form1(stackTrace);
            frm1.Text = "XGIGA Formatter";
            frm1.ShowDialog();
        }
    }

I coded this app in Visual Studio using C#.我使用 C# 在 Visual Studio 中编写了这个应用程序。 In this app, I have to access a binary file from a location using a browse button and choose a saving location after the conversion.在这个应用程序中,我必须使用浏览按钮从某个位置访问一个二进制文件,并在转换后选择一个保存位置。 However, when clicking on the "Start Conversion" button, it keeps showing this UnauthorizedAccessException.但是,当单击“开始转换”按钮时,它一直显示此 UnauthorizedAccessException。 We disabled everything in the computer (firewall etc..) but nothing seems to work.我们禁用了计算机中的所有内容(防火墙等),但似乎没有任何效果。 It keeps showing the exception.它一直显示异常。 Here is the part of the code.这是代码的一部分。

    private void StartConversion1(object sender, RoutedEventArgs e)
    {

        try
        {
            Byte[] a1 = File.ReadAllBytes(filePath1.Text);
            Byte[] a2 = new Byte[(a1.Length) / 2];


            a2[0] = a1[0];
            int i = 2;
            int j = 1;
            while (i < a1.Length)
            {

                a2[j] = a1[i];
                i = i + 2;
                j = j + 1;
            }
            try
            {
                File.WriteAllBytes(savingPath1.Text, a2);
                MessageBox.Show("Conversion Complete");
            }
            catch (UnauthorizedAccessException ex)
            {
                Form3 frm3 = new Form3();
                frm3.Text = "XGIGA formatter";
                frm3.ShowDialog();
            }
        } catch(FileNotFoundException ex)
        {
            string stackTrace = ex.ToString();
            Form1 frm1 = new Form1(stackTrace);
            frm1.Text = "XGIGA Formatter";
            frm1.ShowDialog();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM