最后50分,在线等 ,做文件上传时遇到的问题,解决就给分。 急救!
upfiles.aspx文件:
<form id= "Form1 " method= "post " enctype= "multipart/form-data " runat= "server ">
<INPUT id= "fileUp " runat= "server " name= "File1 " style= "Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 184px "
type= "file ">
<asp:Button id= "btnUpFile " style= "Z-INDEX: 102; LEFT: 472px; POSITION: absolute; TOP: 184px "
runat= "server " Text= "上传 "> </asp:Button>
<asp:Label id= "strState " style= "Z-INDEX: 103; LEFT: 304px; POSITION: absolute; TOP: 248px "
runat= "server "> Label </asp:Label>
</form>
upfiles.aspx.cs文件 的上传按钮触发事件为:
private void btnUpFile_Click(object sender, System.EventArgs e)
{
string filePath= " ",fileExtName= " ",mFileName,mPath;
System.Text.StringBuilder strMsg=new System.Text.StringBuilder( "上传的文件信息: <hr color=red> ");
if( " "!=fileUp.PostedFile.FileName)
{
filePath=fileUp.PostedFile.FileName;//获取文件路径
fileExtName=filePath.Substring(filePath.LastIndexOf( ". ")+1);//取得扩展名
try
{
mPath=Server.MapPath( "upfile/ ");//取得物理路径
mFileName=filePath.Substring(filePath.LastIndexOf( "\\ ")+1);//取得文件名
strMsg.Append( "上传的文件类型: "+fileUp.PostedFile.ContentType.ToString()+ " <br> ");
strMsg.Append( "客户端文件地址: "+fileUp.PostedFile.FileName+ " <br> ");
strMsg.Append( "上传文件的文件名: "+mFileName+ " <br> ");
strMsg.Append( "上传文件的扩展名: "+fileExtName);
fileUp.PostedFile.SaveAs(mPath+mFileName);//保存上传文件到指定目录
strState.Text=strMsg.ToString();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
}
但按下上传按钮时总会提示错误信息为:
System.IO.DirectoryNotFoundException: 未找到路径“d:\inetpub\wwwroot\ybweb\upfile\02.jpg”的一部分。 at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at ybweb.manage.upfiles.btnUpFile_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\ybweb\manage\upfiles.aspx.cs:line 67
请大家指教!急!
------解决方案--------------------它不说没找到路径么,检查下路径有没错
------解决方案--------------------要用相对路径,你不要放在默认的wwwroot\目录下,
你要建虚拟目录、才行、这个问题我同事昨天遇到过、、、、
------解决方案--------------------传上去就是绝对路径吧