Importing a Unicode file into NAV through a dataport

josephdeweyjosephdewey Member Posts: 87
Is there any way to import a Unicode file into Navision?

I'm trying to do a Dataport to import a unicode file with some fields that have Chinese characters, into a company that is set up in Navision to support Chinese (non-Unicode in NAV). But the Dataport doesn't recognize the Unicode characters, since Navision is a non-Unicode program (until NAV 2013).

I could do a conversion of the file before I import it, through Notepad++, to convert the file from Unicode to the Windows Code Page, so Navision could import it.

But, I need to import this file multiple times per day, so I need an automated solution, instead of just a manual solution.

Thanks in advance for your help!
Joseph Dewey
Microsoft Dynamics NAV User

Comments

  • ufukufuk Member Posts: 514
    You can write a dll for conversion and call it in Navision by automation. I prefer this approach if the automation is run by a service or only in the same machine. Otherwise registering the dll can be a problematic issue.
    Ufuk Asci
    Pargesoft
  • josephdeweyjosephdewey Member Posts: 87
    Good thoughts. Anybody have details on how I could do this, or where I could go for resources?
    Joseph Dewey
    Microsoft Dynamics NAV User
  • ufukufuk Member Posts: 514
    Sorry for the late reply, I was on holiday :D
    For the dll part you can search for encoding conversion and writing a com visible dll in dotnet related resources.

    Basically the result will be like the following lines in csharp:
    namespace ChangeColl
    {
        [ComVisible(true)]
        [ProgId("ChangeColl")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [Guid("F104F5DC-9F9F-4BD3-9B77-C5AFEA75881C")] 
        public class ChangeColl
        {
            public void SetColl(string pFilePath)
            {
                if (File.Exists(pFilePath))
                {
                    string text = File.ReadAllText(pFilePath,Encoding.Default);
                    File.WriteAllText(pFilePath, text, Encoding.UTF8);
                }
            }
        }
    }
    

    create your bat files to install and uninstall the dll easily. (using regasm and gacutil)
    install.bat file can have the following lines:
    set regasm=%windir%\Microsoft.NET\Framework\v2.0.50727\regasm.exe
    set gacutil=.\gacutil.exe
    
    %regasm% "ChangeFileCollation.dll" /tlb:-ChangeFileCollation.tlb
    %gacutil% /i "ChangeFileCollation.dll"
    pause
    

    and in navision write a function like:
    IF ISCLEAR(ChangeColl) THEN
      IF CREATE(ChangeColl) THEN BEGIN
        ChangeColl.SetColl(pFilePath);
        EXIT(TRUE);
      END;
    
    EXIT(FALSE);
    

    Hope this helps.
    Ufuk Asci
    Pargesoft
Sign In or Register to comment.