Unauthorized Access Exeption (Access Denied) and XML.

I am trying to get my program to read the information of a game I created on Unity that I burned onto a CD-R. But whenever I do, I get the following error:

Unauthorized Access Exception: Access to the path “E:\GameInfo.xml” is denied.

Here’s the script (c-sharp) I am using just for those who want to investigate (script not done):

using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class MenuGameReader : MonoBehaviour {

//The two slashes ("//") mean unused code or side notes.

public string url = "File:///E:/GameInfo.xml";
public string path = "E:/GameInfo.xml";

public GameObject Canvas;
public Text GameTitleText;

[System.Serializable]
public class ProgramInfo {
	[XmlAttribute("name")] public string name = "";
}

IEnumerator CheckForNewData()
{
	yield return new WaitForSeconds(2);
}
	
IEnumerator Start () {

	Canvas = GameObject.Find("Canvas");
	GameTitleText = GameObject.Find("GameTitle").GetComponent<Text>();
	Debug.Log("Hello");
	WWW w = new WWW(url); 
	yield return w;
	Debug.Log(w.text);
	//yield return StartCoroutine("CheckForNewData");
	Debug.Log("Reading disk, please wait...");
	yield return w;
	print(w.isDone);
	if(w.isDone){
		var xmlSerializer = new XmlSerializer(typeof(ProgramInfo));
		//FileStream stream = File.Open("E:/GameInfo.xml", FileMode.Open);
	        var stream = File.Open(path, FileMode.Open);
		var deserializedGameInfo = xmlSerializer.Deserialize(stream) as ProgramInfo;
		stream.Close();
		ProgramInfo programinfo = deserializedGameInfo;

		Debug.Log(programinfo);
		}
	if (!string.IsNullOrEmpty(w.error)){
            Debug.Log(w.error);
	}
	yield return new WaitForSeconds(4);
	
	}

}

I have never received this issue with the “WWW” method, which I used to load THE SAME FILE! All I’m trying to do is to get my program to display XML, does anyone know if I can load the text data from the XML file through the WWW method? (P.S. The XML file is a local file.) I can show you the XML file upon request if you need it for assisting my issue.

Before you ask, disabling the Real-Time Virus scan and running as an administrator DIDN’T work for me.

Well, just reading the documentation carefully actually explains everything. First of all you used File.Open(String, FileMode). If you scroll down to the “Exceptions” section you will find possible reasons why that method might throw an “UnauthorizedAccessException”. It’s actually the first case:

path specified a file that is
read-only.

Since your file is located on a CD it’s a read-only file. The Open method you used does use the FileAccess “ReadWrite”. Since the file is read-only you can’t open the file with ReadWrite access. You can only use Read access. So by using File.Open(String, FileMode, FileAccess) instead and passing FileAccess.Read as third parameter should solve the problem.

As you can read in the Exceptions section the “UnauthorizedAccessException” would still be thrown when:

path specified a file that is
read-only and access is not Read.

So when using the FileAccess mode ReadWrite or Write you would get this exception on readonly files. But if you use Read it should work just fine.