简体   繁体   English

Windows应用商店应用程序中拒绝访问该路径

[英]Access to the path is denied in Windows Store application

I create Windows Store application. 我创建Windows应用商店应用程序 In MainPage.xaml.cs I want to get data from xml file, but I get error message on line: 在MainPage.xaml.cs中我想从xml文件中获取数据,但是我收到了在线错误消息:

XDocument document = XDocument.Load(filename). 

UnauthorizedAccessException was unhandled by user code 用户代码未处理UnauthorizedAccessException

Access to the path 'C:\\Events Project\\events.xml' is denied. 对“C:\\ Events Project \\ events.xml”路径的访问被拒绝。

Any advice is appreciated. 任何建议表示赞赏。

MainPage.xaml.cs MainPage.xaml.cs中

private EventMan man = new EventMan();

public MainPage()    
{
    this.InitializeComponent();
    this.LoadEvents();
}

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

EventMan.cs EventMan.cs

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

    XDocument document = XDocument.Load(filename);

    ...    
}

You can only access certain locations with Windows Store apps by default, as explained here: 默认情况下,您只能使用Windows应用商店应用访问某些位置,如下所述:

File access and permissions in Windows Store apps Windows应用商店应用中的文件访问和权限

You can put the file in your app's AppData folder. 您可以将文件放在应用程序的AppData文件夹中。 Then you can use the ApplicationData class to freely access the file from there... 然后你可以使用ApplicationData类从那里自由访问文件...

var file = await ApplictionData.Current.LocalFolder.GetFileAsync("events.xml");

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

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