System.UnaithorizedAccessException Error Please Help?

Hello I am working on a J# application it reads files and transmits them back into another folder with different names.

The code section that fails looks like:

For (int i = 0; i < Filenames.length; ++)

If (file.Exists(OutputFolet + "vaad" + i)

{

File.Delete(OutputFOlder + "vaaf" + i"

}

try{

File.copy(FilenamesIdea, outputFolder + "vaad" + i)

}

catch (Throwable t){}

}

I get and error with "System.UnauthorizedException". I'm not sure how to set the exceptions for make it work without crashing on active files. If any one has any info please help

 

This is a Frame app by the way.

 

 

 




Answer this question

System.UnaithorizedAccessException Error Please Help?

  • Royal928

    Please try this.

    The "Files[counter].CopyTo("Your new file name here" , true);"

    The "true" will overwrite any existing files in the destination folder.

    try
    {
    
     System.IO.DirectoryInfo dirFrom = new System.IO.DirectoryInfo("C:\\Lars-Inge\\Questions\\FileMove\\From");
     System.IO.FileInfo Files[] = dirFrom.GetFiles();
     for (int counter = 0; counter < dirFrom.GetFiles().length; counter++)
      Files[counter].CopyTo("C:\\Lars-Inge\\Questions\\FileMove\\To\\" + Files[counter].get_Name() , true);
    }
    catch (System.Exception ex)
    {
     MessageBox.Show(ex.get_Message() + "\r\n" + ex.get_StackTrace());
    }
    

  • System.UnaithorizedAccessException Error Please Help?