How to get value of uploaded image path in variable on button click
<p>I have use these code to upload two images in folder of the root directory and I have given two button to upload separate image.on click of button2 I can upload image and show that image in image control and I also did same for on click of button2. But here I want to get the path of images those I uploaded using Button2 and button3 on the click of button1(compare).</p>

<p>Here is my code that I am using:
I have tried this on Button1 click function: but its not showing any value.</p>

<p>what should I do to get value in to two string variable filename1 and filename2 ?</p>

<pre><code>        //string filename1 = FileUpload1.PostedFile.FileName;
        //Response.Write(filename1);
        //string filename2 = FileUpload2.PostedFile.FileName;
        //Response.Write(filename2);
</code></pre>

<p>ASPX page code:</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Day_8_campairTwoImageUpload.aspx.cs" Inherits="validate.Day_8_campairTwoImageUpload" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;
        &lt;asp:Button ID="Button2" runat="server"
            Text="upload" onclick="Button2_Click" /&gt;&lt;asp:Label ID="StatusLabel" runat="server" Text="Status"&gt;&lt;/asp:Label&gt;
        &lt;br /&gt;&lt;br /&gt;
        &lt;asp:FileUpload ID="FileUpload2" runat="server" /&gt;&lt;asp:Button ID="Button3" 
            runat="server" Text="upload" onclick="Button3_Click" /&gt;&lt;asp:Label ID="StatusLabel1" runat="server"
                Text="Status"&gt;&lt;/asp:Label&gt;&lt;br /&gt;&lt;br /&gt;

    &lt;asp:Button ID="Button1" runat="server" Text="Compar" a onclick="Button1_Click" /&gt;
    &lt;/div&gt;
    &lt;asp:Image ID="Image1" runat="server" Height="100" Width="100"   /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
    &lt;asp:Image ID="Image2" runat="server" Height="100" Width="100" /&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>ASPX.cs page code:</p>

<pre><code>//BUTTON2=CODE TO UPLOAD FIRST IMAGE AND SHOW IT IN IMAGE CONTROL
        protected void Button2_Click(object sender, EventArgs e)
        {

            if (FileUpload1.HasFile)
            {
                try
                {
                    if (FileUpload1.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUpload1.PostedFile.ContentLength &lt; 102400)
                        {
                            //EnsureDirectoriesExist();

                            string filename1 = Path.GetFileName(FileUpload1.FileName);
                            FileUpload1.SaveAs(Server.MapPath(@"~/upload/") + filename1);
                            StatusLabel.Text = "Upload status: File uploaded!";

                            Image1.ImageUrl ="/Upload/"+FileUpload1.FileName.ToString();


                           // string filename1 = Server.MapPath(@"~/upload/") + FileUpload1.FileName;
                           // Response.Write(filename1);
                        }
                        else
                            StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                    }
                    else
                        StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
//BUTTON3=CODE TO UPLOAD SECOND IMAGE AND SHOW IT IN IMAGE CONTROL
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (FileUpload2.HasFile)
            {
                try
                {
                    if (FileUpload2.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUpload2.PostedFile.ContentLength &lt; 102400)
                        {
                            //EnsureDirectoriesExist();

                            string  filename2 = Path.GetFileName(FileUpload2.FileName);
                            FileUpload2.SaveAs(Server.MapPath(@"~/upload/") + filename2);
                            StatusLabel1.Text = "Upload status: File uploaded!";
                            Image2.ImageUrl = "/Upload/" + FileUpload2.FileName.ToString();
                        }
                        else
                            StatusLabel1.Text = "Upload status: The file has to be less than 100 kb!";
                    }
                    else
                        StatusLabel1.Text = "Upload status: Only JPEG files are accepted!";
                }
                catch (Exception ex)
                {
                    StatusLabel1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }


        }

//BUTTON1=CODE TO GET THE PATH NAME OF BOTH UPLOADED IMAGE IN TWO VARIABLE


 protected void Button1_Click(object sender, EventArgs e)
        {


           // string filename1 = FileUpload1.PostedFile.FileName;
            //Response.Write(filename1);
            // string filename2 = FileUpload2.PostedFile.FileName;
            //Response.Write(filename2);


        }

        }
    }
</code></pre>
