2017-02-08 5 views
0

다른 UWP 응용 프로그램에 저장된 데이터에 액세스하지 못했습니다.다른 UWP 응용 프로그램에서 데이터 가져 오기

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; 
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; 
Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatter = 
      new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime"); 

StorageFile sampleFile = await localFolder.CreateFileAsync("example.txt", 
         CreationCollisionOption.ReplaceExisting); 
await FileIO.WriteTextAsync(sampleFile, formatter.Format(DateTime.Now)); 

Here is the official documentation을 : 나는이 코드를 사용하여 UWP 응용 프로그램의 LocalState 폴더에 데이터를 저장할 수 있음을 보았다.

그래서이 코드를 사용하여 첫 번째 UWP 프로젝트에 example.txt라는 파일을 만듭니다.

두 번째 UWP 프로젝트에서 example.txt에 액세스 할 수 있습니까? 그렇다면 어떻게?

답변

1

예. 두 앱이 동일한 게시자에 의해 게시 된 경우에만 가능합니다.

이 폴더 캐시는 다음

PublisherCacheFolder라고 자세하게 설명하는 Blog Post입니다.

데이터를 공유하려는 모든 앱에서 앱 매니페스트에 확장 프로그램을 추가해야합니다.

<Extensions> 
    <Extension Category="windows.publisherCacheFolders"> 
    <PublisherCacheFolders> 
     <Folder Name="Downloads" /> 
    </PublisherCacheFolders> 
    </Extension> 
</Extensions> 

Channel9에 대한 설명이있는 좋은 동영상이 있습니다. 19 분으로 이동하십시오.

아래의 간단한 쓰기 및 읽기 방법은 Blog입니다.

async void WritetoPublisherFolder(string Text) 
{ 
    StorageFolder SharedFolder = Windows.Storage.ApplicationData.Current.GetPublisherCacheFolder("CommonFolder"); 
    StorageFile newFile = await SharedFolder.CreateFileAsync("SharedFile.txt", CreationCollisionOption.OpenIfExists); 
    await FileIO.WriteTextAsync(newFile, Text); 
} 

async Task<string> ReadFromSharedFolder() 
{ 
    StorageFolder SharedFolder = Windows.Storage.ApplicationData.Current.GetPublisherCacheFolder("CommonFolder"); 
    StorageFile newFile = await SharedFolder.GetFileAsync("SharedFile.txt"); 
    var text = await FileIO.ReadTextAsync(newFile); 
    return text; 
} 
+1

덕분에 내가 무엇을 찾고있어 많은! – fandro

2

UWP의 응용 프로그램은 샌드 박스 처리되므로 사용자는 자신의 저장소에 쉽게 액세스 할 수 없습니다. 옵션의 부부 공유 데이터가 있습니다

  • 당신이 적절한 기능을 모든 응용 프로그램에 액세스 할 수 있습니다 KnownFolders를 사용할 수
  • 할 수 있습니다 사용자가 선택한 위치에 use picker to save a file,
  • 할 수 있습니다 use picker to pick 폴더에 앱에 액세스 할 수있는 콘텐츠는
  • 이거나 특정 콘텐츠를 수신하기 위해 등록 된 share data with other apps 일 수 있습니다.
관련 문제