读书人

在上载时,怎么过滤掉一些后缀名

发布时间: 2012-01-09 21:05:42 作者: rapoo

在上载时,如何过滤掉一些后缀名
在asp.net中如何编写程序.不让用户上传某些后缀名的文件. 如 ".bat "的

[解决办法]
if(fileupload1.filename.substring(fileupload1.filename.lastindexof( ' ' '))!= "bat "
{
fileupload1.saveas();
}
[解决办法]
string[] allowedException ={ ".doc ", ".txt " };
string fileException = System.IO.Path.GetExtension(fn).ToLower();
string fn = System.IO.Path.GetFileName(this.FindFile.PostedFile.FileName);
bool ok=false;
for (int j = 0; j < allowedException.Length; j++)
{
if (fileException == allowedException[j])
OK = true;
}
if (OK)
{

}

读书人网 >asp.net

热点推荐