如何在asp.net中使用fileupload控件更改图像

问题描述:

我是asp.net的初学者。

i希望使用fileupload控件显示更改图像。

文件上传控制示例

此链接可以帮助我。但我的问题是如何更改图像。这个链接只保存图片。



请帮忙...

I am beginner in asp.net .
i want to show change image using fileupload control.
File upload control example
This link help me.But my problem is how to change image . this link only save image.

please help...

下面是参考代码。


Below is reference code.

<![CDATA[<%@ Page Language="C#" %>]]>

<script runat="server">
    protected string uploadedImgPath;
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            uploadedImgPath = "/images/" + FileUpload1.FileName;
            FileUpload1.SaveAs(Server.MapPath(uploadedImgPath));
        }
        else
        {
            emptyupload.Text = "Choose your file"; 
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            font-size: larger;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="auto-style1">
   
        Pick Your file from file upload control<br />
        
        <asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
        <br />
        <br />
        <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Save" xmlns:asp="#unknown" />   
        <br />
        <asp:label id="emptyupload" runat="server" xmlns:asp="#unknown"></asp:label>   
    </div>
    </form>
    <p>
        Your Uploaded Image</p>
        <img src="<%=uploadedImgPath%>" />
</body>
</html>