如何为上传的图片添加id属性

时间:2017-12-05 05:46:36

标签: c# asp.net

我想为上传的图片添加id属性如何做到这一点。我试过但没有任何想法。任何帮助都将不胜感激

的.aspx

 <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />   
<hr />
   <asp:Label ID="lblSuccess" runat="server" ForeColor="Green" />
    </div>
    </form>

C#

 protected void Upload(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/") + fileName);

            lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFile.FileName);          

        }
    }

0 个答案:

没有答案