Matt Matt - 1 year ago 124
C# Question

Access to the path is denied in Windows Store application

I create Windows Store application. In MainPage.xaml.cs I want to get data from xml file, but I get error message on line:

XDocument document = XDocument.Load(filename).

UnauthorizedAccessException was unhandled by user code

Access to the path 'C:\Events Project\events.xml' is denied.

Any advice is appreciated.


private EventMan man = new EventMan();

public MainPage()

private void LoadEvents()
this.Events = man.GetAllEvents(@"C:\Events Project\events.xml");


public List<Event> GetAllEvents(string filename)
if (filename == null)
throw new ArgumentNullException("filename");

XDocument document = XDocument.Load(filename);


Answer Source

You can only access certain locations with Windows Store apps by default, as explained here:

File access and permissions in Windows Store apps

You can put the file in your app's AppData folder. Then you can use the ApplicationData class to freely access the file from there...

var file = await ApplictionData.Current.LocalFolder.GetFileAsync("events.xml");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download