本文介绍了仅限FileUpload图片扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个Fileupload,我只想将其用于从工具箱创建的图像,但是在浏览时我只希望允许图片扩展名?
I have created an Fileupload that i only want to use for images that i have created from the toolbox but when browing i only want to allow picuture extensions? anyone that know how i could start?
推荐答案
if (fileupload1.HasFile)
{
FileInfo finfo = new FileInfo(fileupload1.FileName);
string fileExtension = finfo.Extension.ToLower();
/*compare this with a list of acceptable extensions..
if it contains in list then
fileupload1.SaveAs(filename);
else return with a message..*/
}
或者通过javascript,您可以尝试这样..
Or by javascript you can try like this..
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="JavaScript">
function CheckType() {
var id = document.getElementById('fileupload1').value;
if (id != '') {
var myextensions = /(.jpg|.jpeg|.gif)
这篇关于仅限FileUpload图片扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!