1 Attachment(s)
Renaming and Immediately Using a File
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:
Code:
//Pseudocode
File.Move(filePath, filePathRenamed);
oEmail.Attachments.Add(filePathRenamed, Outlook.OlAttachmentType.olByValue, 1, filePathRenamed);
...but I keep on getting the attached error when I do this.
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...
Code:
//Pseudocode
int i = 0;
File.Move(filePath, filePathRenamed);
while (!File.Exists(filePathRenamed)
{
i++;
}
oEmail.Attachments.Add(filePathRenamed, Outlook.OlAttachmentType.olByValue, 1, filePathRenamed);
... to make the program wait until the rename is finished, but it makes no difference: I get the same error.
Can anyone help me out?
Thanks,
Qu.
Re: Renaming and Immediately Using a File
I'm not sure if it will help but try testing the file's Offline attribute and don't try to access the file it's set.