How to get programmatically the number of AppData\Roaming\SDL\ProjectApi folder?

I'm checking Studio 2019 SR2 and found that my code for getting the real default project template is failing...
It's failing because Studio 2019 screwed the folders numbering system which worked for years... Disappointed

So far the numbering system was simple and consistent:

    "Studio2"  {$StudioVersionAppData = "10.0.0.0"}
    "Studio3"  {$StudioVersionAppData = "11.0.0.0"}
    "Studio4"  {$StudioVersionAppData = "12.0.0.0"}
    "Studio5"  {$StudioVersionAppData = "14.0.0.0"}
    "Studio15" {$StudioVersionAppData = "15.0.0.0"}

But now I see that Studio 2019 SR1 - and also SR2 - has AppData\Roaming\SDL\ProjectApi\15.1.0.0 folder :-O :-O :-O

That number does not correspond to anything...
All other such numbered folders have 15.0.0.0 number.
SDLTradosStudio.exe product version is 15.0.0.0, file version is 15.2.0.1041.

So, where does this weird number come from and how do I get it programmatically, please?!
Of course I need it to work 100% realiably across ALL Studio versions, SRs and CUs.

Ultimately, I need to read the AppData\Roaming\ProjectApi\<number>\Sdl.ProjectApi.xml file, so if there is any other way to get its full path, I'm fine with that way too.

  • Hi ,

    You can use the following code sample to identify the default application file; I'll create and publish a sample app later on today.

    private static string GetProjectApiFilePath(string studioInstallationPath)
    {
        var applicationVersion = GetApplicationVersion(studioInstallationPath);
        if (applicationVersion == null)
        {
            return null;
        }

        var applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        var projectApiFolder = Path.Combine(applicationDataFolder, Path.Combine("SDL", "ProjectApi"));
        var projectApiFile = Path.Combine(projectApiFolder, applicationVersion, "Sdl.ProjectApi.xml");

        return File.Exists(projectApiFile) ? projectApiFile : null;
    }

    private static string GetApplicationVersion(string studioInstallationPath)
    {
        var assemblyFile = Path.Combine(studioInstallationPath, "Sdl.ProjectApi.dll");
        return File.Exists(assemblyFile)
            ? System.Reflection.AssemblyName.GetAssemblyName(assemblyFile).Version.ToString()
            : null;
    }

    You can test with the following:

    var studio2014InstallationPath = @"C:\Program Files (x86)\SDL\SDL Trados Studio\Studio3";
    var studio2015InstallationPath = @"C:\Program Files (x86)\SDL\SDL Trados Studio\Studio4";
    var studio2017InstallationPath = @"C:\Program Files (x86)\SDL\SDL Trados Studio\Studio5";
    var studio2019InstallationPath = @"C:\Program Files (x86)\SDL\SDL Trados Studio\Studio15";

    var studio2014ProjectApiFilePath = GetProjectApiFilePath(studio2014InstallationPath);
    var studio2015ProjectApiFilePath = GetProjectApiFilePath(studio2015InstallationPath);
    var studio2017ProjectApiFilePath = GetProjectApiFilePath(studio2017InstallationPath);
    var studio2019ProjectApiFilePath = GetProjectApiFilePath(studio2019InstallationPath);

  • Hello  ,

    New update was done in the SDL Freshstart application (on how to get the Sdl.ProjectApi.xml file, see in the below print screen), the code is also avaialble on our public repository.

    Screenshot of Trados Studio code showing the GetProjectApiFilePath method with a try-catch block logging an error for exceptions.

    With kind regards,

    Florentina Caputa

    With kind regards,

    Florentina Caputa



    Generated Image Alt-Text
    [edited by: Trados AI at 1:19 PM (GMT 0) on 5 Mar 2024]