c# - File locked after sending it as attachment -


i sending file attachment:

            // create  file attachment e-mail message.             attachment data = new attachment(filepath, mediatypenames.application.octet);             // add time stamp information 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 file attachment e-mail message.             message.attachments.add(data); 

and want move file folder, when try this

                    try                     {                         //file.open(oldfullpath, filemode.open, fileaccess.readwrite,fileshare.readwrite);                         file.move(oldfullpath, newfullpath);                      }                     catch (exception ex)                     {                     } 

its throwing exception file being used in process. how can unlock file can moved location?

disposing message fix you. try calling dispose on message before moving file, so:

message.dispose(); file.move(...) 

when disposing mailmessage, locks , resources released.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -