EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Remove signature Office document .docx extension

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#16628
Posted: 06/10/2011 01:12:09
by Mikel Iriarte (Standard support level)
Joined: 06/09/2011
Posts: 5

Hello:

I'm having problems removing signatures from Office documents (.docx, .xlsx). I have the following code:

Code
/// <summary>
        /// Quita la firma a un documento PDF
        /// </summary>
        /// <param name="documentoOrigen">documento origen que se va a a firmar</param>
        /// <param name="documentoOrigen">documento destino en el que se guardar&#225; el doucumento a firmar</param>
        /// <param name="passwordOrigen">Contrase&#241;a del documento PDF origen</param>
        /// <param name="passwordDestino">Contrase&#241;a que tendr&#225; el documento PDF destino</param>
        public void QuitarFirmaOffice(string documentoOrigen, string documentoDestino, string passwordOrigen, string passwordDestino)
        {
            //Inicializamos las librearias
            SBOfficeSecurity.Unit.Initialize();
            //Instanciamos un documento Office
            TElOfficeDocument officeDocument = new TElOfficeDocument();
            string TempPath = DesencriptarOFFICE(documentoOrigen, passwordOrigen);
            try
            {
                //Abrimos el documento Office
                officeDocument.Open(TempPath);
                //Quitamos las firmas
                if (officeDocument.IsSigned)
                {
                    for (int i = 0; i < officeDocument.SignatureHandlerCount; i++)
                        officeDocument.RemoveSignature(i);
                }
                officeDocument.Flush();
                officeDocument.Close();
            }
            catch (SBOfficeCommon.EElOfficeDocumentError)
            {
                throw new Exception("El documento no es v&#225;lido o est&#225; vac&#237;o.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (officeDocument != null)
                    officeDocument.Dispose();
                bool firmado = OfficeEstaFirmado(TempPath, null);
                //Borramos el documento temporal
                if (File.Exists(TempPath))
                {
                    if (!firmado)
                        File.Copy(TempPath, documentoDestino, true);
                    File.Delete(TempPath);
                }
                if (firmado)
                    throw new Exception("No se ha podido quitar la firma al documento.");
            }
        }


What I'm doing wrong?

Thanks,


[ Download ]
#16629
Posted: 06/10/2011 01:21:51
by Eugene Mayevski (EldoS Corp.)

And what your actual problem is? What error are you getting or .. ?


Sincerely yours
Eugene Mayevski
#16631
Posted: 06/10/2011 01:30:08
by Mikel Iriarte (Standard support level)
Joined: 06/09/2011
Posts: 5

The code don´t throw any error, simply after closing the .docx or .xlsx the document still have the signature. This code works well for .doc and .xls but not for the new Office document extensions.

Thanks,
#16632
Posted: 06/10/2011 01:45:43
by Mikel Iriarte (Standard support level)
Joined: 06/09/2011
Posts: 5

I need to know how to remove signatures from .docx and .xlsx documents.
Could you help me?

Thanks,
#16633
Posted: 06/10/2011 05:34:21
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for the samples.
This issue is fixed for the next build that expected at this weekends.
It was caused by a package class that doesn't mark a document as modified in case of part deletion only.

P.S. Your code for deletion signatures is slightly incorrect, you should use:
Code
for (int i = officeDocument.SignatureHandlerCount - 1; i >= 0 ; i--)
   officeDocument.RemoveSignature(i);
#16634
Posted: 06/10/2011 05:46:21
by Mikel Iriarte (Standard support level)
Joined: 06/09/2011
Posts: 5

That's right, my code was incorrect.
Thanks for your quick response.
I will wait for te bug to be fixed.

Thanks a lot!
#16642
Posted: 06/12/2011 08:40:34
by Eugene Mayevski (EldoS Corp.)

JFYI: new build is available on the site.


Sincerely yours
Eugene Mayevski
#16644
Posted: 06/13/2011 01:47:05
by Mikel Iriarte (Standard support level)
Joined: 06/09/2011
Posts: 5

Thanks! Now Works!
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 1301 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!