Premision denied saveasfile kill...
Hi
i am trying to save an attachment for temproray use and then delete it afterwards and i keep getting premission denied error when i want to delete the attachment :/
For Each eItem In Inbox.Items
If eItem.UnRead = True Then
For Each atmt In eItem.Attachments
If Right(atmt.FileName, 3) = "xml" Then
atmtP = "C:\" & atmt.FileName
atmt.SaveAsFile atmtP
'NOW WHEN I TRY TO DO THIS FOR EXAMPLE
kill atmtP ' i get premision denied error
any help would be great thanks...
Re: Premision denied saveasfile kill...
Welcome to the Forums.
Is your "attachment" a file that is open?
Re: Premision denied saveasfile kill...
Hi,
no the file is closed.
what i do is that i loop through the un read emails and save their attachment for temporary use, because the attachment has some xml in it so i parse it and then i need to delete the temporary file. so the file is supposed to be closed. the thing is once i use saveasfile to save a temporary attachment file i can't delete it even if i manually try to delete it from outside outlook until i exit from outlook. somehow outlook takes control over the file i think :S.
Re: Premision denied saveasfile kill...
Is the temp attachment file still have any references tied to it like a file stream or file system object?
Can you post your SaveAs code procedure?
Re: Premision denied saveasfile kill...
yeap your right, i found out the source of the problem, when I save the attachment file
atmt.SaveAsFile atmtP
If ((xmlt.ValidateXML(atmtP, schemaP)) = True) Then '<--PROBLEM WITH THIS METHOD
....
End If
i pass the atmtP to a method which checks if the attachment is of valid xml
schema, when ever i call this method i can't do anything with the file anymore, i think it keeps it open or something, anywayz the xml thingy is
written by a friend using c# and i am just using his .tlb reference, so i have to waite for him to check if he forgot to close the file or something, thanks heaps <>_<>
Re: Premision denied saveasfile kill...
Yup, sounds like atmtP has a reference left instanciated. It may be being passed byref in the arguments which will pass the actual object instead of a copy. .NET pases objects ByRef as a default where VB6/VBA passes ByVal.