2011-12-07 59 views
2

我有一個需要存儲和檢索孤立存儲file.I數據將從Winforms應用程序的文件中存儲數據,但我需要從ASP.NET應用程序中的文件檢索該數據。我已成功地將數據保存在隔離文件通過這裏的WinForms應用是如何在獨立存儲文件中存儲和檢索數據?

  IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain(); 

      string[] fileNames = isoStore.GetFileNames(fileName); 

      if (fileNames != null && fileNames.Length > 0) 
      { 
       foreach (string file in fileNames) 
       { 
        if (file == fileName) 
        { 
         isSuccess = true; 
         break; 
        } 
        else 
         isSuccess = false; 
       } 
      } 

      if (!isSuccess) 
      {     
       oStream = new IsolatedStorageFileStream(fileName, FileMode.Create, isoStore); 
       writer = new StreamWriter(oStream); 
       writer.WriteLine(licenseCode); 
       writer.Close(); 
      } 

在ASP.NET應用我會從分離的存儲文件。該代碼檢索數據如下所示 IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain()的代碼;

  string[] fileNames = isoStore.GetFileNames(fileName);     

      //Retrieve License Code from Isolated storage 
      iStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isoStore); 

      reader = new StreamReader(iStream); 
      String line; 

      while ((line = reader.ReadLine()) != null) 
      { 
       output = line; 
      } 
      return output; 

但我無法檢索存儲在獨立存儲文件從ASP.NET應用程序的數據(字符串[]的文件名= isoStore.GetFileNames(文件名);此字符串[]返回0),其指示無文件存在於機器中。

任何人都可以幫我解決這個問題嗎?

回答

1

孤立的存儲是孤立的(正如名稱所述)。所以你不能訪問不同組件的獨立存儲。我假設你的ASP.NET應用程序與Winform應用程序不在同一個程序集中

+0

是的,你是對的,兩者都是不同的項目,那麼我怎樣才能從ASP.NET應用程序中的獨立存儲文件中檢索數據? – Ramalingam

+0

@Ramalingam:正如fix_likes_coding所述,isolationstorage是孤立的,因此您不能從不同的應用程序訪問它。 – Fischermaen

+0

@Fischermaen:好的,謝謝你的回覆。 – Ramalingam