一下為代碼片段:
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;