1
Answer

Cannot open saved zip files extracted from Outlook Mail

navnit mudaliar

navnit mudaliar

13y
2.2k
1
Hi Everyone,

I've created a small C# application which extracts attachments from outlook emails and saves them to a network location. I can open all of the saved files except for compressed files with "zip" extension.

Files with the "zip" extension can only be opened/extracted via Windows Explorer. If I try to use WinRAR, I get the following error: "The archive is either in unknown format or damaged". WinZip does not work either. If however, I open the email within outlook manually and copy the zip file to my PC, I am able to open the zipped file using WinRAR, WinZip as well as windows explorer.

Part of the code used to save the attachment is shown below.

        Microsoft.Office.Interop.Outlook.MailItem _mailItem;
        ...
        ...       
        _AttachFileName = _mailItem.Attachments[j].FileName;
        _TempAttachmentFile = Path.Combine(_tempFolder.Path, _AttachFileName);

        _mailItem.Attachments[j].SaveAsFile(_TempAttachmentFile);
        ...
        ...

Has anyone faced a similar issue with compressed zip files? If so were you able to resolve the issue?

Any ideas or help on this will be appreciated.

Thanks
Navnit
Answers (1)
1
Amit Gupta
NA 16.5k 25.7k 7y
Hey
 
As your base class is Player which was derived by  Warrior and Sorcerer class, just cast your Player class to the respective derive class to access its field.
 
 
  1. static void Main(string[] args)    
  2. {    
  3.       var player = ChooseClass();    
  4.       if(player is Warrior)    
  5.       {  
  6.          var cType = ((Warrior)player).classtype;  
  7.       }    
  8.       else    
  9.         // Do your rest stuff, same as above to cast to access its variable  
  10.       Console.Clear();    
  11.       Console.WriteLine();    
  12.       Console.ReadLine();    
  13. }    
 
Hope that works ! 
1
Nilesh Shah
NA 22.3k 215k 7y
change this line
  1. Player player = ChooseClass(); 
 
to:
  1. var player = ChooseClass(); 
 
once you know by gettype which type of object is created, then you can write the logic accordingly
0
Joshua Hecht
NA 8 629 7y
Hi Nilesh,
 
I've switched type Player to var in the main method, but I'm still in the same situation because the return type of the method is still Player, and it won't accept var as the return type. Therefore, I still can't access the fields of the Warrior/Sorcerer class because it thinks its just a Player.