469,270 Members | 1,796 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Invalid mail attachment error

Hello,

I'm developing a windows service that monitors a directory (using a
FileSystemWatcher) for newly created files. When a new file is created, I
need to generate an e-mail and send that file as an attachment. This all
working fine except that sometimes the code that adds the attachment fires
before the new file is finished being written to, resulting in an "invalid
mail attachment" error.

What is the best way to deal with this? Is there some way to determine if a
file is not being accessed before trying to attach it? Should I find some way
to delay the attachment by a few seconds? Thanks in advance for your help!

Brian
Jul 21 '05 #1
2 1611
Why not just do this in error handling: if the file is being used, sleep for
a second.

--- N

"bmcelhany" <bm*******@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
Hello,

I'm developing a windows service that monitors a directory (using a
FileSystemWatcher) for newly created files. When a new file is created, I
need to generate an e-mail and send that file as an attachment. This all
working fine except that sometimes the code that adds the attachment fires
before the new file is finished being written to, resulting in an "invalid
mail attachment" error.

What is the best way to deal with this? Is there some way to determine if a file is not being accessed before trying to attach it? Should I find some way to delay the attachment by a few seconds? Thanks in advance for your help!

Brian

Jul 21 '05 #2
That's exactly what I'm thinking, Nick...problem is I'm not sure how to go
about it. I obviously need to create some sort of object (File, FileInfo,
etc.) that has the ability to tell me if the file in question is in use, I
just haven't been able to find something that does that.

"Nick Malik" wrote:
Why not just do this in error handling: if the file is being used, sleep for
a second.

--- N

"bmcelhany" <bm*******@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
Hello,

I'm developing a windows service that monitors a directory (using a
FileSystemWatcher) for newly created files. When a new file is created, I
need to generate an e-mail and send that file as an attachment. This all
working fine except that sometimes the code that adds the attachment fires
before the new file is finished being written to, resulting in an "invalid
mail attachment" error.

What is the best way to deal with this? Is there some way to determine if

a
file is not being accessed before trying to attach it? Should I find some

way
to delay the attachment by a few seconds? Thanks in advance for your help!

Brian


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fraser S | last post: by
2 posts views Thread by bmcelhany | last post: by
4 posts views Thread by Reticulated Ember | last post: by
8 posts views Thread by =?Utf-8?B?cm95SGU=?= | last post: by
2 posts views Thread by Ruud | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.