简单问题如下,请用C#实现:
用户注册时上传个人图片到服务器的同一文件夹(如:UpLoad)下,上传的图片会自动更名为以用户名为文件名保存,当用户多次上传个人图片时,程序在文件夹下查找已存在的图片并替换,以保持文件夹中图片与用户的一一对应。图片格式取用户上传图片的格式。

解决方案 »

  1.   

    asp.net(c#)实现,问题解决即揭帖,再线等,多谢!
      

  2.   

    string strpath=Server.MapPath("")+"\\Images\\"+SaveName
    //SaveName为新的图片名,strpath为保存图片的路径 if(System.IO.File.Exists(strpath))
    {
    Response.Write("<script>alert('对不起,该图片名已经存在,请更换图片名')</script>");
    return;
    }
    else
    {
    myFile.PostedFile.SaveAs(strpath);
    }
      

  3.   

    楼上请:
    Response.Write("<script>alert('对不起,该图片名已经存在,请更换图片名')</script>");
    不要求用户手动更换用户名,系统自动将已存在的同名文件删除,请给出删除已存在文件的代码。
      

  4.   

    if(System.IO.File.Exists(strpath))
       System.IO.File.Delete(strpath);myFile.PostedFile.SaveAs(strpath);
      

  5.   

    fileBrowse为File field控件名,imagePerson为Image控件名     
           string picFullName = this.fileBrowse.PostedFile.FileName;
                string picType = picFullName.Substring(picFullName.LastIndexOf(".")+1);
                string picName = this.txtUserName.Text.Trim()+"."+picType;
                string pic = Server.MapPath("ImagesUp")+"\\"+picName;
                if(System.IO.File.Exists(pic))
                { 
                    File.Delete(pic);
                    this.fileBrowse.PostedFile.SaveAs(pic);
                }
                else
                {
                   this.fileBrowse.PostedFile.SaveAs(pic);
                }
                this.imgPerson.ImageUrl = "ImagesUp"+"\\"+picName;
           运行第一次,上船图片及显示均没问题,第二次从新浏览,上传时图片不能显示,刷新还是第一次上传的图片。何故????高手请了.......
      

  6.   

    string strpath=Server.MapPath("")+"\\Images\\"+SaveName
    if(System.IO.File.Exists(strpath))
    {
    System.IO.File.Delete(strpath);
    }
    else
    {
    myFile.PostedFile.SaveAs(strpath);
    }