Hi guys.
For a program I'm making, I have to rename a file and then immediately attach it to a new outlook message.
I know how to do both:
...but I keep on getting the attached error when I do this.Code://Pseudocode File.Move(filePath, filePathRenamed); oEmail.Attachments.Add(filePathRenamed, Outlook.OlAttachmentType.olByValue, 1, filePathRenamed);
Before I get shouted down because this is an interop error, let me explain: I know that this method works fine if I don't use move to change the file name, and I know that it works fine if I link it to a seperate button and press the second button after the renaming is finished.
My conclusion, therefore, is that it has something to do with the code trying to attach the file while it's still being renamed.
I've tried this...... to make the program wait until the rename is finished, but it makes no difference: I get the same error.Code://Pseudocode int i = 0; File.Move(filePath, filePathRenamed); while (!File.Exists(filePathRenamed) { i++; } oEmail.Attachments.Add(filePathRenamed, Outlook.OlAttachmentType.olByValue, 1, filePathRenamed);
Can anyone help me out?
Thanks,
Qu.




Reply With Quote