fileName)
    {
        if (string.IsNullOrEmpty(fileName))
        {
            lblmsg.Text 
= "Please select Files!";
            
return false;
        }
        
if (fileName.IndexOf("'"> -1)
        {
            lblmsg.Text 
= "File name should exclud qotation marks!";
            
return false;
        }
        
if (fileName.IndexOf("."== -1)
        {
            lblmsg.Text 
= "Unrecognizable file!";
            
return false;
        }
        
int contentSize = FileUpload.PostedFile.ContentLength;
        
if (contentSize > 4470784)
        {
            lblmsg.Text 
= "File size is larger than 4MB!";
            
return false;
        }
        
if (contentSize == 0)
        {
            lblmsg.Text 
= "File size is 0!";
            
return false;
        }

        
//附件類型不允許上傳
        string fileType = fileName.Substring(fileName.LastIndexOf("."+ 1).ToUpper();
        
bool canUploadFileType = false;
        
//允許上傳的類型
        string[] canFilesType = new string[] { "JPG""JPEG""PNG""PDF""PPT""TXT""XLS""DOC" };
        
for (int i = 0; i < canFilesType.Length; i++)
        {
            
if (canFilesType[i] == fileType)
            {
                canUploadFileType 
= true;
            }
        }
        
if (canUploadFileType == false)
        {
            lblmsg.Text 
= "Unacceptable file!";
            
return false;
        }
        
return true;
    }

相关文章:

  • 2021-09-16
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
猜你喜欢
  • 2021-05-03
  • 2021-12-08
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
相关资源
相似解决方案