Asp.net中的FileUpload不提供File Filter功能,而且也不能使用OpenFileDialog。那就只有通过JavaScript实现

<script language="javascript">
function openfile() {
try {
var fd = new ActiveXObject("MSComDlg.CommonDialog");
fd.Filter
= "上传文件 (*.jpg;*.jpeg;*.gif)|*.jpg;*.jpeg;*.gif";
fd.FilterIndex
= 2;
// 必须设置MaxFileSize. 否则出错
fd.MaxFileSize = 128;
fd.ShowOpen();
document.getElementById(
"txtFilePath").value = fd.Filename;
}
catch (e) {
document.getElementById(
"txtFileName").value = "";
}
}
</script>

调用:

 <asp:TextBox ID="txtFilePath" runat="server" Width="300px" />  

<input type="button" onclick="openfile()" value="Browse..." />

以上可以实现web中上传过滤。
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-11-21
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2022-01-31
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-06-21
相关资源
相似解决方案