2014-11-08 2 views
0

Windows Phone 응용 프로그램에서이 코드를 읽고 XML 파일에서 데이터를 쓰면이 코드가 제대로 작동합니다. 그래서 윈도우 8.1 응용 프로그램에서 사용하고 싶지만 내가 그것을 윈도우 8.1 당신은 파일을 읽고, 새로운 API를 사용할 필요가Windows Phone 8.1에서 Windows 8.1로 IsolatedStorageFileStream을 변환하십시오.

public void Read(string strXMLFile) 
    { 
     IsolatedStorageFile isfData = IsolatedStorageFile.GetUserStoreForApplication(); 
     XDocument doc = null; 
     IsolatedStorageFileStream isfStream = null; 
     if (isfData.FileExists(strXMLFile)) 
     { 
      isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Open, isfData); 
      doc = XDocument.Load(isfStream); 
      isfStream.Close(); 
     } 
     else 
     { 
      doc = XDocument.Load(strXMLFile); 
      isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.CreateNew, isfData); 
      doc.Save(isfStream); 
      isfStream.Close(); 
     } 

     var vData = from s in doc.Descendants("Row") select new ColData(s); 
    } 


    public void Write(string strXMLFile) 
    { 
     XElement xml = new XElement("Tabel", 
         from p in this 
         select p.Information); 

     IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()); 
     xml.Save(isfStream); 
     isfStream.Close(); 

    } 
+0

"작동하지 않음"이란 정확히 무엇을 의미합니까? –

+0

이 코드는 Windows Phone 8.1 응용 프로그램에서 작동하지만 Windows 8.1 응용 프로그램 또는 Windows RT App에서는 작동하지 않습니다. – masalahi

+0

그래, 작동하지 않는 내용을 정의하십시오. 예외가 발생 했습니까? 코드가 멈 춥니 다? 정확히 무엇? –

답변

0

와 호환되도록 변환하는 방법, 작동하지 않을 것

var file = await localFolder.GetFileAsync("dataFile.txt"); 
var data = await FileIO.ReadTextAsync(file); 

및 구성원 코드 프로젝트 사이트에서 질문에 대답 DamithSL

var file = await localFolder.CreateFileAsync("dataFile.txt",  CreateCollisionOption.ReplaceExisting); 
await FileIO.WriteTextAsync(file , "data"); 
0

를 작성하는

http://www.codeproject.com/Questions/839861/Convert-IsolatedStorageFileStream-from-Windows-pho

public async Task Read(string fileName) 
    { 
     string text = ""; 
     IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; 

     IStorageFile storageFile = await applicationFolder.GetFileAsync(fileName); 

     IRandomAccessStream accessStream = await storageFile.OpenReadAsync(); 

     using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size)) 
     { 

      byte[] content = new byte[stream.Length]; 

      await stream.ReadAsync(content, 0, (int)stream.Length); 

      text = Encoding.UTF8.GetString(content, 0, content.Length); 

     } 

     XDocument loadedDataH = XDocument.Parse(text); 
     var vPosting = from query in loadedDataH.Descendants("Row") 
         select new clssColPost(query); 
     this.Clear(); 
     AddRange(vPosting); 

    } 


    public async Task Write(string fileName) 
    { 

     XElement xml = new XElement("Tabel", 
          from p in this 
          select p.Information); 


     IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; 

     IStorageFile storageFile = await applicationFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); 

     using (Stream stream = await storageFile.OpenStreamForWriteAsync()) 
     { 
      byte[] content = Encoding.UTF8.GetBytes(xml.ToString()); 
      await stream.WriteAsync(content, 0, content.Length); 
     } 
    } 
관련 문제