问题描述
publicstaticintIntlsUF=0;privatevoidUpFile(){stringFilePath=Server.MapPath("App_Themes/file")+"Files";//保存到服务器的路径HttpFileCollectionHFC=Request.Files;for(inti=0;i<HFC.Count;i++){HttpPostedFileUserHPF=HFC[i];try{if(UserHPF.ContentLength>0){intIntFieldID=CC.GetAutoID("fileID","tb_files");stringstrFileTName="["+IntFieldID+"]"+System.IO.Path.GetFileName(UserHPF.FileName);stringsqlStr="insertintotb_files(fileID,fileName,fileLoad,fileUpDate,fileTrueName)";sqlStr+="values('"+IntFieldID+"'";sqlStr+=",'"+System.IO.Path.GetFileName(UserHPF.FileName)+"'";sqlStr+=",'"+FilePath+"'";sqlStr+=",'"+DateTime.Now.ToLongDateString()+"'";sqlStr+=",'"+strFileTName+"')";SqlConnectionmyConn=CC.Getconnection();myConn.Open();SqlCommandmyCmd=newSqlCommand(sqlStr,myConn);myCmd.ExecuteNonQuery();myCmd.Dispose();myConn.Dispose();UserHPF.SaveAs(FilePath+"App_Themes/file"+strFileTName);//将上传文件存放到指定文件夹中IntlsUF=1;}}catch{Response.Write(CC.MessageBox("处理出错!","上传文件.aspx"));return;}}if(IntlsUF==1){Response.Write(CC.MessageBox("上传成功!","上传文件.aspx"));}else{Response.Write(CC.MessageBox("请选择上传文件!","上传文件.aspx"));}}这是一个上传文件的网站,当选择好文件要上传时,一直提示“处理错误”。我哪里写错了?来位前辈帮帮忙,谢谢了。红色字体的那个路径要怎么写?
解决方案
解决方案二:
System.IO.Path.GetFileName(UserHPF.FileName);//这样是拿上传后的文件名。直接用UserHPF.FileName就行了