Very Urgent regarding deleting the images from a folder

asp.net , csharp , Vb.net India
  • 8 years ago

    hi, i have a query regarding deleting the images stored in a folder...

    my query is:

    how store the images to the folder and displaying the image names in a listbox and deleting the selected image from a folder when we select the name in the listbox using c#

    plz help me out...its very urgent

    thanks and regards, pinky

  • 8 years ago

    //ASPX PAGE

    //code behind protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { GetFiles(); } } private void GetFiles() { string Dir = "~/UploadFolder/"; DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(Dir));

        ListBox1.DataSource = dirInfo.GetFiles("*.*");
        ListBox1.DataBind();
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string Dir = "~/UploadFolder/";
        FileUpload1.SaveAs(Server.MapPath(Dir + FileUpload1.FileName));
        Label1.Text = "File uploaded successfully";
        GetFiles();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string Dir = "~/UploadFolder/";
        foreach (ListItem li in ListBox1.Items)
        {
            if (li.Selected)
            {
                File.Delete(Server.MapPath(Dir + li.Text));
            }
        }
        Label1.Text = "Selected files deleted successfully.";
        GetFiles();
    }
    
  • 8 years ago

    hi, thanks a lot for ur answer...it worked out and helped me...i need another help regarding ur answer...how to display the image when we select the image name in the listbox..very urgent..plz do help me out

    thanks and regards, pinky

  • 8 years ago

    hi, thanks a lot for ur answer...it worked out and helped me...i need another help regarding ur answer...how to display the image when we select the image name in the listbox..very urgent..plz do help me out

    thanks and regards, pinky

  • 8 years ago

    hi,

    set ListBox AutopostBack='true'...

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { foreach (ListItem li in ListBox1.Items) { if (li.Selected) { Image1.ImageUrl = "~/Photos/Ramesh/" + li.Value; } } }

  • 8 years ago

    on select change write the following code

    Image1.ImageUrl = Server.MapPath(Dir + list1.SelectedItem[0].Text );

    i guess this should work.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”