2012-09-06 33 views
0

我是C#.NET的新手。從多個* .resx文件訪問和讀取數據

我需要從我的本地文件夾訪問* .resx文件,然後從每個* .resx文件中檢索數據。 我正在爲此創建一個Windows應用程序。所以首先,一旦我給該文件夾的路徑,它找到了那裏的文件,但現在,我怎樣才能讀取這些文件,並從它們獲取數據到RAM上的臨時數據庫。

私人無效buttonBrowseSource1_Click(對象發件人,EventArgs的)

{

 FolderBrowserDialog selectPathDialog = new FolderBrowserDialog(); 
     if (selectPathDialog.ShowDialog() == DialogResult.OK) 
     { 
      DirectoryInfo di = new DirectoryInfo(selectPathDialog.SelectedPath); 
      FileInfo[] RESXFiles = di.GetFiles("*.resx"); 

      if (RESXFiles.Length == 0) 
      { 

       UpdateStatus("No RESX files found in this directory. Please check the folder/path again."); 
      } 
      else 
      { 

       UpdateStatus("Total " + RESXFiles.Length + " RESX files found in this directory.); 
       textBoxSource1.Text = selectPathDialog.SelectedPath; 

      } 
     } 
     else 
     { 
      UpdateStatus("Missing directory! Please try again."); 
     } 
    } 

太謝謝你了。

+0

「UpdateStatus」是形式豐富的文本框只是爲了顯示狀態信息。 – Indigo

回答

1

爲此使用ResXResourceReader Class

+0

我試過......我正在創建一個處理文件的新類,但得到了一個例外,路徑無法訪問。我試過所有文件都解鎖。可能是我創建的課程有問題。 – Indigo

0
// Gets the value of associated with key "MyKey" from the local resource file for a given culture ("~/MyPage.aspx.en.resx") or from the default one ("~/MyPage.aspx.resx") 
object keyValue = HttpContext.GetLocalResourceObject("~/MyPage.aspx", "MyKey", culture); 

使用這樣的事情

窗戶此鏈接可能有用的,你

http://www.c-sharpcorner.com/uploadfile/yougerthen/handle-resource-files-read-and-write-into-a-resx-file-programmatically-part-iii/

+0

我可以幫助你更多,對你有用 –

+0

謝謝,但不是真的幫助.... 我正在創建Windows應用程序,我需要獲得不同的resx文件併合並他們的數據來創建新的resx文件。 – Indigo

+0

可能我編輯的故事會幫助你 –