How to delete an uploaded file

Last post 08-06-2013, 1:54 PM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  08-05-2013, 2:21 PM 77814

    How to delete an uploaded file

    Hi,

     

    can i use AttachmentRemoveClicked event to delete an uploaded file?

     

    <%@Page Language="c#"%>
    <%@Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI"%>               
    <html>
    <head>
       <title>Simple Upload</title>

       <script runat="server">
            void InsertMsg(string msg)  
            {
                ListBoxEvents.Items.Insert(0, msg);
                ListBoxEvents.SelectedIndex = 0;
            }
     
           void Uploader1_FileUploaded(object sender, UploaderEventArgs args)
            {
                InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");

                args.CopyTo("c:\\temp\\"+args.FileName);
            }   

     

            void Uploader1_AttachmentRemoveClicked(object sender, UploaderEventArgs args)
            {
                InsertMsg("File deleted! " + args.FileName + ", " + args.FileSize + " bytes.");

                XXXXXXXXXXXXXXXXXXXXXXXXXXX

            }  
      </script>

    </head>

    <body><form id="Form1" method="post" runat="server">
           <div>
                        <CuteWebUI:UploadAttachments ID="Uploader1" runat="server"
                           InsertButtonID="btnUpload" OnFileUploaded="Uploader1_FileUploaded"

                           onattachmentremoveclicked="Uploader1_AttachmentRemoveClicked">
                        </CuteWebUI:UploadAttachments>
               <p>
                    Server Trace:
                   <br/>
                   <asp:ListBox runat="server" ID="ListBoxEvents"/>
               </p>
           </div>
       </form>
    </body>
    </html>

     

  •  08-06-2013, 1:54 PM 77820 in reply to 77814

    Re: How to delete an uploaded file

    Hi ttyrone,

     

    Please try the example page below, first check if the upload file exists in the store folder, then delete it by the c# code.

     

    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5.   
    6. <html xmlns="http://www.w3.org/1999/xhtml">  
    7. <head id="Head1" runat="server">  
    8.     <script runat="server">  
    9.     
    10.       
    11.   
    12.         protected void uploader1_AttachmentRemoveClicked(object sender, AttachmentItemEventArgs args)  
    13.         {  
    14.             //if the upload file has saved into the photos folder  
    15.             if (File.Exists(Server.MapPath("~/photos/" + args.Item.FileName)))  
    16.             {  
    17.                 //delete it  
    18.                 File.Delete(Server.MapPath("~/photos/" + args.Item.FileName));  
    19.             }  
    20.         }  
    21.   
    22.         protected void uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)  
    23.         {  
    24.             for (int i = 0; i < args.Length; i++)  
    25.             {  
    26.                 args[i].CopyTo("~/photos/" + args[i].FileName);  
    27.             }  
    28.         }  
    29.     </script>  
    30. </head>  
    31.   
    32. <body>  
    33.     <form id="Form1" runat="server">  
    34.         <CuteWebUI:UploadAttachments runat="server" ID="uploader1" OnAttachmentRemoveClicked="uploader1_AttachmentRemoveClicked" OnUploadCompleted="uploader1_UploadCompleted">  
    35.         </CuteWebUI:UploadAttachments>  
    36.     </form>  
    37. </body>  
     

    Regards,

     

    ken 

View as RSS news feed in XML