在asp.net中如何编写程序.不让用户上传某些后缀名的文件. 如 ".bat"的

解决方案 »

  1.   

    if(fileupload1.filename.substring(fileupload1.filename.lastindexof('''))!="bat"
    {
     fileupload1.saveas();
    }
      

  2.   

    string[] allowedException ={ ".doc", ".txt" };
     string fileException = System.IO.Path.GetExtension(fn).ToLower();
    string fn = System.IO.Path.GetFileName(this.FindFile.PostedFile.FileName);
    bool ok=false;
     for (int j = 0; j < allowedException.Length; j++)
                            {
                                if (fileException == allowedException[j])
                                    OK = true;
                            }
                            if (OK)
                            {
                              
    }