| Author |  | 
      
        | mnoreen Newbie
 
  
 
 Joined: 17 July 2012
 Location: United States
 Online Status: Offline
 Posts: 19
 | 
          The SaveToFolder() method on the Attachment class doesn't seem to quite be doing what is documented.
           | Posted: 31 March 2020 at 8:06am | IP Logged |   |  
           | 
 |  
 I have a mail message that is loaded, then there's a foreach loop to go through the attachments and calling the SaveToFolder() method on each one. Pretty simple. Except, this one mail message so happens to have the same file attached 2x.
 
 I've stepped through this code in the debugger.  The .FileName property is different for both attachments.  But the SaveToFolder() method isn't using the FileName property, it appears to be using the .FilenameOriginal property.
 
 If I change the code to pass "false" in the SaveToFolder() method.  It will save out the 2nd attachment now with a "[1]" postfix to the filename. But then, that doesn't match the attachment's .filename property.
 
 
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | mnoreen Newbie
 
  
 
 Joined: 17 July 2012
 Location: United States
 Online Status: Offline
 Posts: 19
 | 
          
           | Posted: 31 March 2020 at 8:09am | IP Logged |   |  
           | 
 |  
| Code: 
 
    
    | 
      
       | foreach (Attachment attachment in msg.Attachments)
 {
 if (attachment.IsInline)
 continue;
 
 attachment.SaveToFolder(workFolder, false);
 }
 
 |  |  |  
 This code works in that both files are saved, but the 2nd file is saved with postfix on the filename rather than using the .FileName property from the attachment.
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          Neither FilenameOriginal nor FileName are assigned to the filename generated by SaveToFolder method. Suffix appended to FileName is to distinguish between attachments with the same name in .Attachments collection. SaveToFolder, on other hand, appends a completely different suffix which is to distinguish between files with the same filename in the target folder. Before SaveToFolder call, it's not known which filename will be actually assigned (we don't know if the file with the same name already exists in that folder or not).
           | Posted: 31 March 2020 at 9:36am | IP Logged |   |  
           | 
 |  
 So, SavedAs is assigned AFTER SaveToFolder and it's the only property which can be reliably used as a referenced to the saved file.
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | mnoreen Newbie
 
  
 
 Joined: 17 July 2012
 Location: United States
 Online Status: Offline
 Posts: 19
 | 
          Thank you Alex, I worked around it.  I was just going off the code definition/comments that are a part of the Mailbee object browser (for example, I put cursor over the Attachment declaration in my code, hit F12 (Go To Definition).
           | Posted: 01 April 2020 at 9:53am | IP Logged |   |  
           | 
 |  
 
 
| Code: 
 
    
    | 
      
       | // Remarks:
 //     This method saves the attachment content to the folder under the actual filename
 //     of the attachment (which is taken from MailBee.Mime.Attachment.Filename property).
 
 |  |  |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | mnoreen Newbie
 
  
 
 Joined: 17 July 2012
 Location: United States
 Online Status: Offline
 Posts: 19
 | 
          It's a tricky situation.  We want to save then remove all non-inline attachments from an .eml file, and finally resave the .eml.  So we reworked the code to call
           | Posted: 06 April 2020 at 12:02pm | IP Logged |   |  
           | 
 |  
 
 
| Code: 
 
    
    | 
      
       | SaveAll(string folderName, bool ignoreInlineAttachments)
 
 |  |  |  
 Then use a reverse iteration to remove the attachments from the MailMessage object.
 
 
 
| Code: 
 
    
    | 
      
       | for (int i = msg.Attachments.Count - 1; i >= 0; i--)
 {
 if (msg.Attachments.IsInline)
 continue;
 
 msg.Attachments.RemoveAt(i);
 }
 
 |  |  |  
 But this seems like there's a possibility it could get out of sequence.  Would it be possible to get a function equivalent to the SaveAll() method with the "ignoreInlineAttachments" parameter?
 
 
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          Sorry, I could not understand what you're asking for.
           | Posted: 07 April 2020 at 1:29am | IP Logged |   |  
           | 
 |  
 A function equivalent to the SaveAll() method with the "ignoreInlineAttachments" parameter? - How would it differ from SaveAll with this parameter (which is already there)?
 
 Regards,
 Alex
 
 
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | mnoreen Newbie
 
  
 
 Joined: 17 July 2012
 Location: United States
 Online Status: Offline
 Posts: 19
 | 
          I was hoping that there could be RemoveAll(bool ignoreInlineAttachments) method that worked *like* the SaveAll() method w/ that boolean parameter.
           | Posted: 10 April 2020 at 1:26pm | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          Got it now, thanks. No, that would be a too special method for a general-purpose library.
           | Posted: 11 April 2020 at 6:14am | IP Logged |   |  
           | 
 |  
 BTW, when do you get "out of sequence" situation?
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  |