傳入m_file=Fileupload的ID
private bool CheckFiles(string m_file)
{
bool m_return = true;
{
bool m_return = true;
FileUpload myFL = new FileUpload();
myFL = (FileUpload)this.roundpanel.FindControl(m_file);
roundpanel是放FileUpload的容器
roundpanel等於是FileUpload的上一層才能控制FileUpload
String fileExtension = System.IO.Path.GetExtension(myFL.FileName).ToLower(); //取得上傳的檔案類型
String fileExtension = System.IO.Path.GetExtension(myFL.FileName).ToLower(); //取得上傳的檔案類型
//檢查檔案大小
if (myFL.PostedFile.ContentLength > 0)
{
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
return m_return;
}
}
}
return false;
{
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
return m_return;
}
}
}
return false;
}
沒有留言:
張貼留言