2013-06-01 4 views
1

Windows 저장소 응용 프로그램을 만듭니다. MainPage.xaml.cs를 나는 XML 파일에서 데이터를 얻을 싶지만 줄에 오류 메시지가 :Windows 저장소 응용 프로그램에서 경로에 대한 액세스가 거부되었습니다.

XDocument document = XDocument.Load(filename). 

UnauthorizedAccessException 사용자 코드에 의해 처리되지 않은했다

C '경로에 대한 액세스가 : \ 이벤트 Project \ events.xml '이 (가) 거부되었습니다.

모든 조언을 받으실 수 있습니다.

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

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

    XDocument document = XDocument.Load(filename); 

    ...  
} 

답변

3

여기에 설명 된대로 만, 기본적으로 윈도우 스토어의 앱을 특정 위치에 액세스 할 수 있습니다

File access and permissions in Windows Store apps

파일을 앱의에 넣을 수 있습니다.3210 폴더에 있습니다. 그런 다음 ApplicationData 클래스를 사용하여 자유롭게 파일에 액세스 할 수 있습니다.

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

많은 도움을 주셔서 감사합니다. – Matt

관련 문제