Archived Forum Post

Index of archived forum posts


SaveRelatedItem not always generating unique filename?

Jan 21 '14 at 07:30

I seem to have an odd issue with using the SaveRelatedItem function, in that it doesn't always seem to save with a new filename when a file already exists, or, if it is, it is not returning this new filename using "GetRelatedFileName" after the save is finished.

The weird thing is, it seems to work sometimes, and other times it does not. Particularly with the filenames "image001.png" and "image002.png" it seems to have an issue - or at least those are two I have noticed. It also seems to be a problem more frequently with messages that are replies or forwards. What happens if when generating the random 4 characters to put on the end of the filename, it ends up with a filename which still already exists - would this cause the save to fail? Or would it keep trying to generate a unique name until it found one?

Here is my code (C#) - can anyone shed any furhter light on this, please?

POPemail.OverwriteExisting = false;

//now do embedded images int embed_count = POPemail.NumRelatedItems;

for(int loop_attach=0; loop_attach<embed_count;loop_attach++) { //MessageBox.Show(attachments[loop_attach].Name); string EmbedFileName = POPemail.GetRelatedFilename(loop_attach); POPemail.SaveRelatedItem(loop_attach,attachment_path); string SavedEmbedFileName = POPemail.GetRelatedFilename(loop_attach); email.addAttachment(attachment_path+"\"+SavedEmbedFileName+"(****)"+SavedEmbedFileName); }