上传文件
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);
if(fileExtName == "024")
{
try
{
//取得与 Web 服务器上的指定虚拟路径相对应的物理文件路径。
mPath=Server.MapPath("Data/WeatherForecast/");
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());
}
}
else
{
strMsg.Append("上传失败,此文件不合法!");
strState.Text = strMsg.ToString();
}
}
else
{
strMsg.Append("请选择文件!");
strState.Text = strMsg.ToString();
}
}posted on 2006-02-15 08:55 mjgforever 阅读(452) 评论(0) 收藏 举报

浙公网安备 33010602011771号