博客园 首页 联系 订阅 管理

 <asp:FileUpload ID="FileUpload1" runat="server" />
                                            <asp:Image ID="login" runat="server" />
                                            <asp:Label ID="myimg" runat="server" Text="Label" Visible="false"></asp:Label>

修改

 this.login.ImageUrl = "../" + ds.Tables[0].Rows[0]["proimg"].ToString();
            this.myimg.Text = ds.Tables[0].Rows[0]["proimg"].ToString();

添加时: 

string newimg1 = "";
        string newname1 = "";
        string fileName1;
        fileName1 = this.FileUpload1.PostedFile.FileName.ToString().Trim();

        if (fileName1 != "")
        {
            string fileType1 = fileName1.Substring(fileName1.LastIndexOf(".") + 1).ToLower();
            newname1 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "." + fileType1;
            newimg1 = "image/" + newname1;
            FileUpload1.SaveAs(Server.MapPath("../image/" + newname1));
            try
            {
                File.Delete(Server.MapPath(this.login.ImageUrl));
            }
            catch (Exception)
            {

            }
        }

确定修改时:

string newimg1 = "";
        string newname1 = "";
        string fileName1;
        fileName1 = this.FileUpload1.PostedFile.FileName.ToString().Trim();

        if (fileName1 != "")
        {
            string fileType1 = fileName1.Substring(fileName1.LastIndexOf(".") + 1).ToLower();
            newname1 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "." + fileType1;
            newimg1 = "image/" + newname1;
            FileUpload1.SaveAs(Server.MapPath("../image/" + newname1));
            try
            {
                File.Delete(Server.MapPath(this.login.ImageUrl));
            }
            catch (Exception)
            {

            }
        }
        else
        {
            string yuanming1 = this.login.ImageUrl;
            newimg1 = yuanming1.Remove(0, 3);

        }

posted on 2011-10-27 16:48  $蔷  阅读(260)  评论(0)    收藏  举报