hi guys, Can you help me. How can I delete the uploaded photo ?? if I click the delete button message box appear and asking if I am sure to delete the photo, if I choose the Ok button the image was still there. How can I remove that?? what are the right code for this. Thanks.

Recommended Answers

All 3 Replies

you have to give us more information, how are you uploading photos, how are you attempting to delete them, what code, language etc. etc.

I use ASP.net, C#. here the code behind.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadPic.aspx.cs" Inherits="UploadPic" %>

<!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>Mandalay Support System</title>
    <link href="css/index.css" rel="stylesheet" type="text/css" />
    <link rel="SHORTCUT ICON" href="images/mandalay.ico" />
</head>
<body>
    <form id="form1" runat="server">
    <!--#include file="header.aspx"-->
    <div>
     <br />
        <br />
         <br />
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload" />
        <asp:Label runat="server" ID="textoutput"></asp:Label>
        <br />
        <br />
        <asp:Image ID="Image1" runat="server" Height="234px" style="margin-bottom: 1px" 
            Width="281px" />
        <br />
&nbsp;<asp:Button ID="Button2" runat="server" Text="Set as primary picture" 
            onclick="Button2_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button3" runat="server" Text="delete" onclick="Button3_Click" 
            Visible="False" />
        <br />
        <br />
    </form>
     <!--#include file="footer.aspx"-->
</body>
</html>


C# code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class UploadPic : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object Source, EventArgs evArgs)
    {
        string strFileNameOnServer = FileUpload1.FileName.ToString();
        string strBaseLocation = "D:\\mss2\\upload\\other\\";
        string absolute_path = MapPath("~/" + FileUpload1.FileName);
        string relative_path = "~/" + FileUpload1.FileName;

        if (FileUpload1.HasFile)
        {

            FileUpload1.SaveAs(absolute_path);
            Image1.ImageUrl = relative_path;


        }

        if ("" == strFileNameOnServer)
        {
            textoutput.Text = "Error - a file name must be specified.";

            return;
        }

        if (null != FileUpload1.PostedFile)
        {
            try
            {
                FileUpload1.PostedFile.SaveAs(strBaseLocation + strFileNameOnServer);
                textoutput.Text = "uploaded successfully";

            }
            catch (Exception e)
            {
                textoutput.Text = "Error saving <b>" +
                  strBaseLocation + strFileNameOnServer + "</b><br>" + e.ToString();


            }

        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
      //  if (Button3.Text != "delete")
        {
         //   Image1.Visible = true;
         //   Button3.Visible = true;
        }
            //OnClientClick = "return confirm('Are you sure you want to delete?');"
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
}

can you help me??
Thanks

using asp.net , php code you can delete any image file from folder but for that you need to give full rights to this folder for delete image file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.