Mike-T

Hi,

I am sent an update file from a third party using email. They are not able to use FTP, and I am one of many users so their side of the system cannot be changed.

The update file is attached and called update.txt, an outlook rule places the emails in . There is a maximum size that file can be (on the third parties side) which is about 10K.

So if there are 300,000 updated items to send this equates to about 135K which results in 135 emails all containing an attached file called 'update.txt' and all sent at the same time. I Create a unique file name and save the file using .SaveAsFile

The code for this is below.

foreach (Outlook.MailItem UGM in TFILE.Items)
{
count++;
foreach (Outlook.Attachment TFILE in UGM.Attachments)
{
string saveas = string.Format(@"d:\TUPDATE\{0:0000}{1:00}{2:00}{3:000}{4}",
UGM.SentOn.Year,
UGM.SentOn.Month,
UGM.SentOn.Day,
count,
TFILE.FileName
);

try
{

TFILE.SaveAsFile(saveas);

}
catch (Exception ex)
{

string mess = ex.Message;
}
}
}

The issue is everytime a file is saved, it gets written out to a temporary location first by outlook. on my PC this equates to

C:\Documents and Settings\MailHandler\Local Settings\Temporary Internet Files\OLK1C9

The first file is saved in the temporary folder as update.txt, the second as update.txt (1) etc.

Thiss is fine, until the 100th file which fails. The reason for this is that outlook will not create update.txt (100), when i get the following exception

ex.Message "Cannot save the attachment. Can't create file: update.txt. Right-click the folder you want to create the file in, and then click Properties on the shortcut menu to check your permissions for the folder." string

The temporary files are not deleted until the outlook session is successfully terminated.

My guess is that I could replicate this behavior just by trying to do a saveas on each of the files in outlook without using VSTO at all.

I have a solution, which is that I delete the temporary file after each saveas call, but I think this is a little dirty. My problem is that I cannot be certain on another machine that the files will be in OLK1C9.

Is there a way to either cause a purge of the temporary directory from VSTO or at least retrieve the location of the driectory Or if anyone has a better solution please let me know.

Thanks

Mike



Re: Visual Studio Tools for Office Problem Saving Attachment's with the same (sent) file name. How to clear outlook internet temporary files?

Sue Mosher - Outlook MVP

Mike-T wrote:

I have a solution, which is that I delete the temporary file after each saveas call, but I think this is a little dirty.

I think that's what you'll need to do

My problem is that I cannot be certain on another machine that the files will be in OLK1C9. Is there a way to either cause a purge of the temporary directory from VSTO or at least retrieve the location of the driectory Or if anyone has a better solution please let me know.

As the article at http://support.microsoft.com/kb/296115/ explains, the location of the secure temp folder is randomly generated unless a specific location has been set in the registry. Given that the parent folder is always the same, it shouldn't be too hard to figure out the temp folder, even if OutlookSecureTempFolder is not set explicitly.





Re: Visual Studio Tools for Office Problem Saving Attachment's with the same (sent) file name. How to clear outlook internet temporary files?

Mike-T

Sue,

Thanks for the reply and the link!

The kb article links to this http://support.microsoft.com/kb/817878/ which has the 2003 reg entry (not that it is hard to work out!)

Mike