2017-06-18 57 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 
}