2017-06-18 76 views
-3
private void Form1_Load(object sender, EventArgs e) 
    { 
     var webClient = new WebClient(); 
     string readHtml = webClient.DownloadString("http://yourdomain.com/yourfolder/vars.txt"); 
     string line = ""; 
     while ((line == webClient.readHtml()) != null) 
     { 
      string[] components = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); 
      users.Add(components[0]); 
      pass.Add(components[1]); 
     } 

     TimeLabel.Text = (DateTime.Now.ToString() + " System time at load"); 
     Text = "Admin Login"; 
    } 

這個代碼可以用戶名和密碼從一個文本文件,並在接下來的IF(這裏沒有顯示)將檢查如果登錄相同文件中....的登錄C#代碼不工作

+0

所以....我們猜測什麼是不工作? –

+0

是的,我不知道任何修復程序 – SkyCityCZ

+0

你必須告訴我們它是如何工作的。你有錯誤嗎?你用調試器完成了這個方法嗎? – Amy

回答

0
string line = ""; 
while ((line == webClient.readHtml()) != null) 

強烈地看起來像從StreamReader讀取代碼的行,例如每次讀入一行。

WebClient.DownloadString(string)然而整個文件讀入一個字符串。所以你必須做這樣的事情來獲得單行

string[] splt=readHtml.Split('\n');//or different presentation of line break 
for(int i=0; i<splt.Length; i++){ 
    //split your components from splt[i] here 
    //and add them to your attributes or whatever 
}