Problem with custom properties

Hi everyone

I have a code in C# that reads a .dot file and deletes some custom properties from this file and saves it as .dot. I am using Aspose library .

I have an other tool that reads and works with this saved file and this tool just can work with .dot file in whitch their text typed cusom properties are Ansi or UTF8

I tried to convert properties to ansi or UTF8 manually in my C# code , but unfortunately the created file is not acceptable in external tool.

I dont know if there is any built in function in Aspose to handle the custom propeties of type text, if they should be converted to ansi or UTF8?
Has anyone any idea?

Regards

@nsh.germo Could you please attach your input and output document along with code that will allow us to reproduce the problem here for testing? We will check the issue and provide you more information.

Hi Alexey . Thank you for reply. Of course I can. But my files are .dot and it seems that here is not possible to attach .dot files. :roll_eyes: :roll_eyes:

@nsh.germo You can zip the files and attach them here.

Ok. I did it
files.zip (34.8 KB)

and here is my c# code

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Word;
using Aspose.Words;
using Document = Aspose.Words.Document;
using Microsoft.Office.Core; 

class Program
{
    static void Main(string[] args)
    {
        string sourceFilePath = @"D:\MyVorlagen\G1101006.dot";
        string targetFilePath = @"D:\my\G1101006.dot"; 

        // Now proceed with Aspose.Words processing
        var license = new License();
        license.SetLicense(@"Resources\Aspose.Words2.lic");

        try
        {
            Document doc = new Document(sourceFilePath);

            var list = new List<string>()
            {
                "e_gcosy_iaz",
                "e_gcosy_iaz_akten",
                "e_prozessname",
                "e_unterprozess",
                "e_formulartyp"
            };
            dynamic newPrp = DeleteCustomProperties(doc, list);

            doc.CustomDocumentProperties.Clear();
            foreach (dynamic prop in newPrp)
            {
                doc.CustomDocumentProperties.Add(prop.Name, prop.Value);
            }

            doc.Save(targetFilePath, SaveFormat.Dot);
            Console.WriteLine("Document processed and saved successfully.");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Aspose Error: {ex.Message}");
        }

        static object DeleteCustomProperties(Document doc, List<string> propertiesToDelete)
        {
            var propertiesFound = new List<object>();

            foreach (var property in doc.CustomDocumentProperties)
            {
                if (!propertiesToDelete.Contains(property.Name))
                {
                    propertiesFound.Add(property);
                }
            }

            return propertiesFound;

        }
    }
}

@nsh.germo Thank you for additional information. It looks like the problem is reproducible after simple open/save the document using Aspose.Words. MS Word detects a problem with the file and opens it in protected view.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26914

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you so much

1 Like