Reputation: 2470
I have written a winform app and have created a installation program using Inno Setup so that a custom file extension is associated with it.
The application is setup so that if the associated file type is double clicked then the application automatically opens and loads the file. This works fine from if the file is double clicked from the desktop or file explorer.
However, we have noticed an issue when trying to open a file attachment from inside Outlook. This error is being generated:
System.UnauthorizedAccessException
I have caught the error in my application and checked the file path that is supplied to the program. It doesn't exist in the file system (when I try to browse to it).
C:\User\MyUserName\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook\MXIIIP00\MyFilename.CustomExtension
The section after ...\Microsoft\Windows\ doesn't exist (as far as I can see).
Has anyone else encountered this issue and know how to solve it?
UPDATE:
If I open a dos prompt - I can actually get to this location even though it is not shown in Windows Explorer.
UPDATE 2:
If I copy the path directly into Windows Explorer I can see the files here too. However if I double click the file from here - my application still cannot load the file.
UPDATE 3:
The file saved by Outlook (and that my app is trying to open) appears to be empty. Which would explain why my app can't process it. Outlook appears to be doing something to the file when I send it. It starts off as 72KB when I send it, but when I receive it - it is 252B.
Upvotes: 1
Views: 766
Reputation: 2470
Okay so as it turns out there was two issues here.
The first was to do with how I was testing this feature. To simulate the file being sent to a customer I used Outlook to send an email with my file as an attachment to myself. For some (as yet unknown) reason, Outlook takes it upon itself to send me an empty file. When I logged into an external email client and sent the file to Outlook the file remained intact.
However, my application still wouldn't open it.
The second issue was the temporary file being created with the Read Only attribute being set. Once I set up my application to turn this off, it all worked fine.
Upvotes: 2
Reputation: 1892
It´s a problem of AUTHORIZATION.
You may try to run your app AND the Outlook in ADMIN MODE to get success - at least it´s mandatory, run both at the same authorization level.
Or even try to open your attachment in the Windows TEMP folder... but I guess you won´t get it from within Outlook if you don´t, programatically, extract the attachment to that folder and open it.
Upvotes: 2