Adding new files to existing GS project through Studio Desktop API

Hi,

according to http://producthelp.sdl.com/SDK/ProjectAutomationApi/2017/html/5457cb35-5a41-432a-8f37-058ae23f2c4f.htm, you can add a new project file to a server project simply by checking it it. I tried it this way:

_sdlProject = new FileBasedProject(sdlProjectPath, gsUseWindowsAuthentication, gsUser, gsPassword);
var tmp = _sdlProject.AddFiles(new[] {"d:\\temp2.txt"})[0];
_sdlProject.SetFileRole(new [] {tmp.Id}, FileRole.Translatable);
var at = _sdlProject.RunAutomaticTask(new[] {tmp.Id}, AutomaticTaskTemplateIds.Scan);
_sdlProject.Save();

_sdlProject.CheckinFiles(new [] {tmp.Id}, "Temp", (sender, args) =>
{

});

However, CheckinFiles() returns immediately, and control never gets into the progress event handler. Indeed, the file does not get checked it. Am I missing something maybe? 

thanks,

Tamas

  • Just adding the resolution that Tamás shared with me as he resolved this problem himself using reflection. He said that the problem was that newly added files were not in state “Checked out” (and through the API he couldn’t check out new files), so they couldn’t be checked in. He worked around it with reflection: asked for a reference to the internal project file objects, and set the “CheckedOutTo” field manually:

    var getProjectFiles = (Func<Guid[], IProjectFile[]>)Delegate.CreateDelegate(typeof(Func<Guid[], IProjectFile[]>), proj, typeof(FileBasedProject).GetMethod("GetProjectFiles", BindingFlags.Instance | BindingFlags.NonPublic));

    var pf = getProjectFiles(new[] {file.Id})[0];
    var sg = pf.Settings.GetSettingsGroup<LanguageFileServerStateSettings>();
    sg.CheckedOutTo.Value = "username";

    proj.CheckinFiles(new[] { file.Id }, "", (sender, args) =>
    {
    Console.WriteLine(args.PercentComplete);
    });