Results 1 to 2 of 2

Thread: Renaming and Immediately Using a File

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    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.
    Attached Images Attached Images  
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width