none
无法用CustomValidator验证FileUpload控件上传文件的扩展名,求助! RRS feed

  • 问题

  •     protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {

            string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
            string[] allowedExtensions = { ".doc", ".wps", ".txt" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                try
                {
                    args.IsValid = (fileExtension == allowedExtensions[i]);
                }
                catch
                {
                    args.IsValid = false;
                }
            }
        }

    2010年12月11日 10:30

答案

全部回复