none
File corrupted warning shows after attachment.PropertyAccessor.SetProperty() and GetProperty() used in outlook attachments? RRS feed

  • Question

  • Hi,

    I have developing outlook addin using VS2010.

    I have an issues in attachment.

    1.I have get an attachment property and modified then reassemble original content.Other files like (doc,pdf,jpg) are opens normally.but microsoft documents like .docx,.xls are showing warning like,"your file are corrupted,you want to recover?" warning.After i have click yes it gives an original document.why its happening?How can i resolve it?

    and also have an another issue.

    2.attachments properties are get and set in Outlook 2010,2013 works.But not works in outlook 2007.i have search the issue,Attachment.PropertyAccessor.SetProperty() not read more than 8kb.but my attachment is just 2kb.it will also gives an error.How can i use in 2007?

    Wednesday, May 21, 2014 5:27 AM

Answers

  • Are you able to reproduce the issue with encrypting Office files with a standalone windows forms application?

    It looks like it is not related to Outlook at all. Am I right?

    • Marked as answer by Sanju Monu Friday, May 23, 2014 6:37 AM
    Thursday, May 22, 2014 10:04 AM

All replies

  • Hello Sanju,

    Do you have any antivirus software installed on the PC?

    > But not works in outlook 2007

    Could you please be more specific? Did you try to debug the code? What error or exception do you get in the code?

    Also I'd recommend checking the list of running COM add-ins. Did you try to disable all of them?

    Finally, do you have the latest updates and service packs installed for Office/Outlook?

    Wednesday, May 21, 2014 12:18 PM
  • Thanks for your reply Eugene.

    In outlook 2007:

    When I am using the attachment.PropertyAccessor, I am getting following exception.

    The property "http://schemas.microsoft.com/mapi/proptag/0x37010102" does not support this operation.

    In outlook 2007 developing machine doesn't have any antivirus.

    But the below issues are occured in other development machine.I am developing that machine has a Avast Antivirus.

    I have get an attachment property and modified then reassemble original content in Outlook 2010 and 2013.Other files like (doc,pdf,jpg) are opens normally.but microsoft documents like .docx,.xls are showing warning like,"your file are corrupted,you want to recover?" warning.After i have click yes it gives an original document.why its happening?How can i resolve it?

    Wednesday, May 21, 2014 1:32 PM
  • Sanju,

    Outlook 2007 doesn't allow to read large property values. This is a well known issue. Please take a look at the Byte Stream from Mail Attachment MAPIOBJECT  forum thread which states the following:

    What happens at a MAPI level is PropertyAccessor is using a MAPI HrGetOneProp call. That will fail on data over about 8K and then you fall back to getting the property as an IStream. In 2007 Outlook doesn't do that with PropertyAccessor due to performance reasons and because of the cost of implementing that functionality. So with PropertyAccessor in 2007 you can write larger properties but not read them back.

    In Outlook 2010 that is fixed and you can read the attachment content even for very large attachments.

    As a workaround you may use the OpenProperty method provided by Extended MAPI. The method allows reading large property values.

    > "your file are corrupted,you want to recover?" warning

    What exactly are you doing in the code and when? Could you please be more specific?

    Wednesday, May 21, 2014 2:03 PM
  • Eugene,

    i have get that attachment content in byte array using attachment.PropertyAccessor.GetProperty().

    after getting that byte array properties,i will encrypt that byte arrays using rijndael method and replace that in using attachment.PropertyAccessor.SetProperty().

    Done to Reverse the above process in receiver side.It works in all other documents like PDF,DOC,JPG etc...

    But while open the microsoft documents,it gives the below warning.

    the file aaa.docx cannot be opened because there are problems with the contents.

    Then click OK,it shows other warning dialog like below.

    Word found unreadable content in aaa.docx.Do you want to recover the contents of this document?If you trust the source of this documnet,click Yes.

    Then Click Yes.it shows Original Content.

    So,why it will occured.If my encryption/decryption method wrong means,How other files working good.

    Got it Eugene?

    Thanks 

    Sanju

    Thursday, May 22, 2014 9:26 AM
  • Are you able to reproduce the issue with encrypting Office files with a standalone windows forms application?

    It looks like it is not related to Outlook at all. Am I right?

    • Marked as answer by Sanju Monu Friday, May 23, 2014 6:37 AM
    Thursday, May 22, 2014 10:04 AM
  • Eugene.

    i think your right.I was already tried in outside.it gives produce the same problem.I will confirm you within 30 minutes.K

    Thanks

    Sanju

    Thursday, May 22, 2014 10:23 AM
  •  Eugene,

    I was tried the below code.it works fine.there is no warning produce this method.

    byte[] myByteArray = System.IO.File.ReadAllBytes("D:\\myteam.xlsx");   

    FileStream fs = new FileStream("D:\\myteam new.xlsx", FileMode.Create, FileAccess.ReadWrite);

    BinaryWriter bw = new BinaryWriter(fs);   

    bw.Write(myByteArray);

    bw.Close();

    But i should get the attachment from outlook,not in local drive.How can i get the outlook attachment content from outlook.And how can i set that property again in outlook attachment.

    And also tested get the attachment Content in byte array using attachment.PropertyAccessor.GetProperty().

    then using that byte array in filestream method to create a file.it also open normally.After Encrypt and Decrypt that content,then using  the attachment byte array  in filestream method for create a file,that file throws that warning.

    So,i think Encryption Decryption has created problem.My Encryption Decryption method given Below.

    public byte[] EncryptBytes(byte[] inputBytes, string passPhrase, string saltValue)        {            RijndaelManaged RijndaelCipher = new RijndaelManaged();   

    RijndaelCipher.Mode = CipherMode.CBC;            byte[] salt = Encoding.ASCII.GetBytes(saltValue);         

    PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, salt, "SHA1", 2);          ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(password.GetBytes(32), password.GetBytes(16));            MemoryStream memoryStream = new MemoryStream();           

    CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);            cryptoStream.Write(inputBytes, 0, inputBytes.Length);      cryptoStream.FlushFinalBlock();            byte[] CipherBytes = memoryStream.ToArray();           

    memoryStream.Close();            cryptoStream.Close();            return CipherBytes;        }

    public byte[] DecryptBytes(byte[] encryptedBytes, string passPhrase, string saltValue)        {            RijndaelManaged RijndaelCipher = new RijndaelManaged(); 

    RijndaelCipher.Mode = CipherMode.CBC;            byte[] salt = Encoding.ASCII.GetBytes(saltValue);         

    PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, salt, "SHA1", 2);         

    ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(password.GetBytes(32), password.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(encryptedBytes);            CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);            byte[] plainBytes = new byte[encryptedBytes.Length];     

    int DecryptedCount = cryptoStream.Read(plainBytes, 0, plainBytes.Length);            memoryStream.Close();            cryptoStream.Close();            return plainBytes;        }


    Got it Eugene?

    Thanks

    Sanju




    • Edited by Sanju Monu Thursday, May 22, 2014 11:51 AM
    Thursday, May 22, 2014 11:05 AM
  • Sanju,

    The Outlook object model doesn't provide any property or method for working with attachments on the fly. You need to save them in the disk first and then read the file from the disk. However, you may use a low level code based on Extended MAPI functions. It allows to read and write the attachment content on the fly.

    Thursday, May 22, 2014 8:04 PM
  • Eugene,

    Thanks for spending your valuable time.

    that issue was fixed..FlushFinalBlock() function is the problem for ms Documents.Thank u.

    Now,we go for an previous problem.thats Focus problem.

    i tried below code:

    Outlook._Explorer explorer = oApp.ActiveExplorer();
    Outlook.MAPIFolder initialFolder =explorer.CurrentFolder;
    explorer.CurrentFolder = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);
    explorer.SelectAllItems();
    explorer.CurrentFolder = initialFolder;
    Marshal.ReleaseComObject(mailItem);
    mailItem = null;

    But it not works.Actually i manually select other mailitem and come to decrypt attachment mailitem while its focused.it works.Now i want to kno, how to select other mailitem and come again to that attachment mailitem.And i was also tried the below code.

    explorer.SelectAllItems();

    explorer.RemoveFromSelection(mailItem); explorer.ClearSelection(); explorer.AddToSelection(mailItem);

    Thanks

    Sanju

    Friday, May 23, 2014 7:07 AM
  • Hello Sanju,

    Your initial post there doesn't contain such questions. I'd recommend asking separate questions in new forum threads, not mixing various questions in the single forum thread. Thus, forum readers may recognize questions and answers easier.

    Based on the code listed above I can conclude that you don't release underlying COM objects instantly. I'd suggest starting from reviewing the code and releasing each object in place. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN.

    Friday, May 23, 2014 7:36 AM
  • Eugene,

    K.thanks.

    Regards

    Sanju

    Friday, May 23, 2014 8:49 AM