点燃自己

才发现已成尘

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


public bool UserIDfromFile(string userID)
    {
        bool result = false;
        string strFileName = HttpContext.Current.Server.MapPath(@".\file") + @"\userInfo.txt";
        if (!System.IO.File.Exists(strFileName))
        {
            throw new Exception(strFileName + "打开失败!");
            result = false;
        }
        try
        {
            string strFileContents = string.Empty;
            FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(fs, System.Text.Encoding.Default);
            strFileContents = reader.ReadToEnd();
            strFileContents.Replace("\r\n", "");
            string[] Items = strFileContents.Trim().Split('=');
            if (Items.Length >= 2)
            {
                string userinfo = strFileContents.Split('=')[1].Trim();
                string[] userIDs = userinfo.Split(',');
                for (int i = 0; i < userIDs.Length; i++)
                {
                    if (userID == userIDs[i].Trim())
                    {
                        result = true;
                    }
                }
            }
            fs.Close();
            reader.Close();
        }
        catch
        {
            result = false;
        }
        return result;
    }

posted on 2014-11-27 11:01  爱吃糖豆的猪  阅读(155)  评论(0编辑  收藏  举报