File Locked after adding it as attachement

No Comments

I was encountering a problem whereby when I was adding an attachement to be sent by email :-

// Create  the file attachment for this e-mail message.

Attachment data = new Attachment(filePath, MediaTypeNames.Application.Octet);

// Add time stamp information for the file.

ContentDisposition disposition = data.ContentDisposition;

disposition.CreationDate = System.IO.File.GetCreationTime(filePath);

disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath);

disposition.ReadDate = System.IO.File.GetLastAccessTime(filePath);

// Add the file attachment to this e-mail message.

message.Attachments.Add(data);

this same file was being locked and could not be moved to a “processed” folder.  Spent a couple of hours tried to figure out why.  Then I found out what the problem was.

The line of code that did the trick was

message.Dispose();

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

Related posts:

  1. Adding an MVc.NET design template to your project

Leave a Reply

Blog WebMastered by All in One Webmaster.