Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:42:47+00:00 2026-06-05T23:42:47+00:00

I have use these code to upload two images in folder of the root

  • 0

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).

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

what should I do to get value in to two string variable filename1 and filename2 ?

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

ASPX page code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Day_8_campairTwoImageUpload.aspx.cs" Inherits="validate.Day_8_campairTwoImageUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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

ASPX.cs page 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 < 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 < 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);


        }

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:42:49+00:00Added an answer on June 5, 2026 at 11:42 pm

    You may use ViewState/Session/HiddenField to save the path of uploaded file in Click handler of button2 and button3.

    protected void Button2_Click(object sender, EventArgs e)
     {
       if (FileUpload1.HasFile)
        {
          .....
          ViewState["file1"]=Server.MapPath("~/upload/" + FileUpload1.FileName);
          ....
        }
     }
    
     protected void Button3_Click(object sender, EventArgs e)
     {
       if (FileUpload2.HasFile)
        {
          .....
          ViewState["file2"]=Server.MapPath("~/upload/" + FileUpload2.FileName);
          ....
        }
     }
    

    In button1_click handler,

    protected void Button1_Click(object sender, EventArgs e)
    {
       if(ViewState["file1"]!=null)
          Label1.Text=ViewState["file1"].ToString();
       if(ViewState["file2"]!=null)
          Label2.Text=ViewState["file2"].ToString();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy ASP.NET/VB.NET WebSite. There several App_Code modules/code files that use types
I have below code to insert a style into DOM (there is a use
I have a array of names and I want to use these names for
I have an IDictionary, now I want to use these values in a selectlist.
I have a list of Func's in a class called ValidationMethods. I use these
I have a dll developed using C++. Now I wish to use these functions
I have an android.graphics.bitmap and an android.net.Uri both of these I can use anyway
i have a php script that resize image to three different resolutions on upload.
I have a Web Application project where the users can upload images to the
I am using uploadify plugin to upload images. The main code is like: <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.