2013-03-11 34 views
0

當我運行隔離存儲 - opeation不允許/而拷貝HTML文件中的Windows Phone

IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
myStore.CopyTextFile("HTDocs\\help.html", true); 

我有錯誤: 「不允許操作上IsolatedStorageFileStream。」它從tutorial。我應該如何解決這個問題?

public static class ISExtensions 
    { 
     public static void CopyTextFile(this IsolatedStorageFile isf, string filename, bool replace = false) 
     { 
      if (!isf.FileExists(filename) || replace == true) 
      { 
       StreamReader stream = new StreamReader(TitleContainer.OpenStream(filename)); 

       IsolatedStorageFileStream outFile = isf.CreateFile(filename); 
       // 

       // 
       string fileAsString = stream.ReadToEnd(); 
       byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(fileAsString); 

       outFile.Write(fileBytes, 0, fileBytes.Length); 

       stream.Close(); 
       outFile.Close(); 
      } 
     } 
} 
+0

你執行多個線程這種方法嗎? – SolarBear 2013-03-11 20:15:17

+0

絕對不是。 – boski 2013-03-11 20:17:36

回答

0

嘗試這樣:

// isolated storage 
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
// access to resource files 
StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri(@"HTDocs\help.html", UriKind.Relative)); 
using (Stream origFileStream = streamInfo.Stream) 
{ 
    // open the filestream for the isostorage file and copy the content from the original stream 
    using (IsolatedStorageFileStream fileStream = myStore.CreateFile("help.html")) 
    { 
     origFileStream.CopyTo(fileStream); 
     origFileStream.Close(); 
    } 
}