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
Post a Comment