UnauthorizedAccessException: Understanding How Access to the path '...' is denied

Asked 2 years ago, Updated 2 years ago, 332 views

I am currently trying to save the captured image in the game, but the following error occurred when I tried to write the file as shown in the last line of code:

UnauthorizedAccessException: Access to the path '...'is denied

There may be many reasons why access was denied, but none of the methods I tried myself worked.

  • Uncheck "read-only" in the specified folder properties.
  • Run Unity as an administrator with administrator privileges.

I tried these, but they didn't work.
Please give me some advice on what other measures you have to take.

Texture2D text=newText2D (CamTex.width, CamTex.height, TextureFormat.RGB24, false);
    RenderTexture.active=CamTex;
    tex.ReadPixels(newRect(0,0,CamTex.width,CamTex.height),0,0);
    varTodayNow=System.DateTime.Now;
    fileName=eventName+"_"+TodayNow.Year.ToString()+"_"+TodayNow.Month+"_"+TodayNow.Day+"_"+TodayNow.ToLongTimeString()+"_"+takingPictures.Count+".png";
    tex.name = fileName;
    tex.Apply();

    byte [ ] bytes = tex.EncodeToPNG();
    var path=Path.Combine(Application.persistentDataPath, "Pictures", fileName);
    Debug.Log(path);
    File.WriteAllBytes (path, bytes);

https://teratail.com/questions/288059
I'm also asking a question.

c# unity3d

2022-09-30 21:51

1 Answers

It's solved.
I deleted the Pictures folder you specified in the hierarchy and created it again, and it worked fine!
I'm worried that I don't know the cause clearly, but this time it was helpful.
Thank you for your cooperation.
UnauthorizedAccessException:Access to the path'...'is denied troubleshooting


2022-09-30 21:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.