Need Javascript DeleteAllAttachments...

Last post 05-21-2009, 2:15 PM by CodeSlinger. 3 replies.
Sort Posts: Previous Next
  •  05-12-2009, 12:22 PM 52074

    Need Javascript DeleteAllAttachments...

    I need to be able to call the DeleteAllAttachments() from Javascript, is it possible?  I have not been able to get this code or something similar to work, please help.
    1.     <script type="text/javascript">  
    2.         var uploaderid='<%=UploadAttachments1.ClientID %>';   
    3.         function DoDeleteAllAttachments()   
    4.         {   
    5.             var uploader=document.getElementById(uploaderid);   
    6.             uploader.deleteallattachments();   
    7.         }
    Filed under:
  •  05-12-2009, 9:36 PM 52097 in reply to 52074

    Re: Need Javascript DeleteAllAttachments...

    Hi,
     
    the attachments list is server side state.
     
    There's 2 solution for it :
     
    A. call a button.click() and let it postback, call the DeleteAllAttachments() at server side.
     
    --
     
    B. you can just hide the table ( Attachments1.GetItemsTable().ClientID ) , set a flag to a hidden field , and call the DeleteAllAttachments() at server side OnLoad event if the hidden field is setted.
     
    Regards,
    Terry
  •  05-13-2009, 10:03 AM 52119 in reply to 52097

    Re: Need Javascript DeleteAllAttachments...

    Terry,
         Thank you very much for answering my question.   I have an additional question related to the same issue.  If the files that were uploaded to UploaderTemp are marked as persisted and the Attachment object is disposed, then shouldn't the persisted uploaded files be deleted (I know that persisted files are deleted if 6 hrs old)? 
     
    1. <script type="text/javascript">  
    2.         var uploaderid='<%=UploadAttachments1.ClientID %>';   
    3.         function DoDeleteAllAttachments()   
    4.         {   
    5.             var uploader=document.getElementById(uploaderid);   
    6.             uploader.dispose();   
    7.         }

    Thanks again!

  •  05-21-2009, 2:15 PM 52401 in reply to 52119

    Re: Need Javascript DeleteAllAttachments...

    FYI, I was trying to clean up the persisted temporary files after uploading the files to the database but the files were not being released when I tried to call DeleteAllDocuments after calling OpenStream. The correct call is as follows:

    using (Stream stream = AttachmentItem.OpenStream())

    {

    stream.Read(byteArraydata, 0, AttachmentItem.FileSize);

    }

    //save to database

    //call DeleteAllAttachments();

    Hope this helps others...

View as RSS news feed in XML