我的上传控件是html组件中的file filed 将他转化为服务器控件运行 代码如下:
HttpPostedFile hpf=F.PostedFile;
int cl=hpf.FileName.Length;
if(cl>0)
{
if(hpf.FileName=="")
{
RegisterStartupScript("","<script>alert('你上传的文件不能为空!')</script>");
}
else
{
string kuo=Path.GetExtension(hpf.FileName).ToLower();
if(kuo==".jpg" || kuo==".gif" || kuo==".bmp" )
{
if(hpf.ContentLength<660000)
{
filename=DateTime.Now.ToString("yyyMMdd")+Path.GetFileName(hpf.FileName);
string filepath=Server.MapPath("loadfile/");
hpf.SaveAs(filepath+filename);
}
else
{
RegisterStartupScript("","<script>alert('请将你所上传的文件控制在600kb内!')</script>");
}
}
else
{
RegisterStartupScript("","<script>alert('上传图片的格式要为jpg,gif,bmp!')</script>");
}
}
}
else
{
filename=face;
}
conndb cdb=new conndb();
int i=cdb.reg(xm,mm,filename,xb,qm,yx,wt,da,lz);
FormsAuthentication.SetAuthCookie(i.ToString(),false);