一下为代码片段:
privatebooleansavefiles()
{
//得到file表单元素
httpfilecollectionfiles=httpcontext.current.request.files;
try
for(intintcount=0;intcount<files.count;intcount++)
httppostedfilepostedfile=files[intcount];
stringfilename,fileextension;
//获得文件名字
filename=system.io.path.getfilename(postedfile.filename);
if(filename!="")
//获得文件名扩展
fileextension=system.io.path.getextension(filename);
//可根据不同的扩展名字,保存文件到不同的文件夹
//注意:可能要修改你的文件夹的匿名写入权限。
postedfile.saveas(system.web.httpcontext.current.request.mappath("upfiles/")+filename);
}
returntrue;
catch(system.exceptionex)
returnfalse;