Re: How to delete an uploaded file

  •  08-06-2013, 1:54 PM

    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 Complete Thread