2012-02-09 43 views
0

中獲取字符串值我有一個包含多個字符串值(構成我的表單標籤)的txt文件。 我怎樣才能得到這個值,從這個文件中,喜歡的東西:從我的Web應用程序中的App_Code文件夾

Label1.Text = GET從CONSTANT.TXT文件

字符串的Label1是否有可能,或更好地遵循另一種方式?

回答

1

我想你會更好地利用資源 http://msdn.microsoft.com/en-us/library/ms227427.aspx

一旦你創建你的資源,你可以簡單地使用它們這樣

<asp:Button ID="Button1" runat="server" 
Text="<%$ Resources:WebResources, Button1Caption %>" /> 

非常簡單

+0

謝謝Marcuz,我會嘗試使用Resources。 Luigi – Ciupaz 2012-02-09 11:26:28

0

試試這個代碼,你可以能夠以兩種方式讀取txt文件。

(1路)

 string value = File.ReadAllText(Server.MapPath("~/App_Code/t.txt")); 


     string[] ar={"\r\n"}; 

     string[] split = value.Split(ar,StringSplitOptions.RemoveEmptyEntries); 

(2路)

TextReader tr = new StreamReader(@"Path of appcode"); 

    //Reading all the text of the file. 
    Console.WriteLine(trs.ReadToEnd()); 

    //Or Can Reading a line of the text file. 
    Console.WriteLine(trs.ReadLine()); 

    //Close the file. 
    trs.Close(); 

    Console.WriteLine("Press any key to exit..."); 
    Console.ReadKey(); 

啤酒花它的幫助。

+0

這個解決方案的問題是,我必須在時間只有一個值, 把它作爲我的標籤的標題。 Luigi – Ciupaz 2012-02-09 09:37:32

+0

我已經編輯我的code.try第一種方式。你可以得到值的字符串集合..在你的代碼中利用你的需求。 – Jigs 2012-02-09 10:03:02

相關問題