C#判断文件名是否合法


C#判断文件名是否合法,如下

    private bool IsFileNameValid(string name)
    {
             bool isFilename = true;
            string[] errorStr =new string []{"/","\\",":",",","*","?","\"","<",">","|"};

            if (string.IsNullOrEmpty(name))
            {
                isFilename= false ;
            }
            else
            {
                for(int i=0;i<errorStr .Length ;i++)
                {
                    if(name.Contains (errorStr[i]))
                    {
                        isFilename = false;
                        break;
                    }
                }
            }
        return isFilename;
    }

posted @ 2006-08-15 11:03  czh  阅读(3498)  评论(1编辑  收藏  举报