使用<input type="file">上传文件出错,求解
报错如下:地址获取没问题啊,求解!!
代码如下!!
<form id="form1" runat="server">
<div>
<input type="file" name="upload" size="2" class="file_real" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
string fileName = Request.Form["upload"];--------------------编程问答-------------------- string fileName = Request.Files[0]; --------------------编程问答-------------------- var fileName = Request.Files[0]; --------------------编程问答-------------------- HttpPostedFile file = Request.Files[0];
// 获取相对地址
string strFileNameMapPath = Server.MapPath("upload/");
fileName = System.IO.Path.GetFileName(fileName);
// 文件的全地址
string strFullFileName = strFileNameMapPath + strCompanyName + "\\" + fileName;
// 存入数据库的地址
string strPath = strCompanyName + "/" + fileName;
// 文件的存放文件夹地址
string strMapPath = strFileNameMapPath + strCompanyName;
// 判断上传文件夹是否存在
if (System.IO.Directory.Exists(strMapPath))
{
// 判断该图片已经上传
if (System.IO.File.Exists(strFullFileName))
{
Response.Write("该文件已经存在!");
}
else
{
// 进行上传操作
upload.PostedFile.SaveAs(strFullFileName);
}
}
else
{
// 创建文件夹
System.IO.Directory.CreateDirectory(strMapPath);
upload.PostedFile.SaveAs(strFullFileName);
}
tring fileName = file.FileName; --------------------编程问答-------------------- Request.Files[0];或者用Request.Files;然后遍历集合 --------------------编程问答-------------------- 你的项目路径为何这么逗? --------------------编程问答-------------------- 楼主的项目亮了. --------------------编程问答-------------------- 可以试一下把路径名称改为英文名称 --------------------编程问答-------------------- Request.Files[0].SaveAs(strFullFileName);
多生产点种子吧
补充:.NET技术 , ASP.NET