日期:2014-05-19  浏览次数:20497 次

asp.net网页中不用服务器控件可以上传文件吗?
在asp.net   的网页中,采用以下服务器控件 <input   id= "myFile "   type= "file "   name= "myFile "   runat= "server "> 可轻易实现上传文件,可如果仅使用html静态控件如 <input   name= "myFile "   type= "file "   /> ,也能实现上传文件吗???  
哪位大侠帮小弟解决一下。最好能给出代码。

------解决方案--------------------
private bool SavePicture()
{
/// '遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
/// '检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
fileExtension = System.IO.Path.GetExtension(fileName);

#region 更改名字
string writename = DateTime.Now.ToString( "yyyyMMddHHmmss ") + fileExtension;

if (File.Value != " ")
{
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath( "../MemberImage/ ") + writename);
memberimage = "MemberImage/ " + writename;
}
else
{
memberimage = hidImage.Value;
}
#endregion
}
return true;
}
catch (System.Exception Ex)
{
return false;
}
}
------解决方案--------------------
function AddApply()
{
var fileext=document.getElementById( "File ").value.substring(document.getElementById( "File ").value.length-4,document.getElementById( "File ").value.length);
fileext=fileext.toLowerCase();

if (!(fileext== '.gif ' || fileext== '.jpg '))
{
if(document.getElementById( "hidImage ").value== " ")
{
document.getElementById( "lbPic ").innerText= '图片不属于GIF与JPG类型 ';
eval( "tbShow.style.display=\ "\ "; ");
return false;
}
else
{
return true;
}
}
return true;
}

function ImageShow()
{
var filepath;
if(document.getElementById( "File ").value.length> 0)
filepath=document.getElementById( "File ").value;
document.getElementById( "imgshow ").src=filepath;
document.getElementById( "imgshow ").width=128;
document.getElementById( "imgshow ").heigth=125;

var oFileChecker = document.getElementById( "imgshow ");
var FileMaxSize = 50;//限制上传的文件大小,单位(k) lbPic innerText