FileUpload 未将对像引用到实例,马上结
protected void Button1_Click(object sender, EventArgs e)
{
if (User.Identity.Name == " ")
{
Response.Write( " <script> window.alert( '登录超时,请重新登录 ');window.location= '/user/login.aspx '; </script> ");
return;
}
string filename = FileUpload1.PostedFile.FileName; //取得文件名
int i = filename.LastIndexOf( ". ");
string newext = filename.Substring(filename.LastIndexOf( ". ") + 1).ToLower(); //取得文件扩展名
//生成新的图片名
string NewFileName = FileUpload1.PostedFile.ContentLength.ToString() + "_ " + DateTime.Now.ToString( "yyyyMMddhhmmss ") + ". " + newext;
string dateming = DateTime.Now.ToString( "yyyy-MM-dd "); //取得日期(创建目录)
if (newext != "jpg " && newext != "bmp " && newext != "gif " && newext != "jpge ")
{
Response.Write( " <script> window.alert( '文件格式不正确,请检查文件类型。 '); </script> ");
return;
}
if (FileUpload1.PostedFile.ContentLength > = 512000)
{
Response.Write( " <script> window.alert( '图片太大!请控制在500K以下! '); </script> ");
return;
}
string rootpath = Server.MapPath( "/images/Up/ " + dateming);
if (!Directory.Exists(rootpath))
{
System.IO.Directory.CreateDirectory(rootpath);
}
string serverpath = Ser