I'm automating the process of creating Trados Studio projects locally, then uploading them to GroupShare via the REST API.
When uploading I first of all create an empty project using this API method...
This returns the ID of the created empty project. Then I create a local FileBasedProject
object, create a package from it, then upload the package to...
This works - the server-based project does get published.
However, if I want to do anything with the local FileBasedProject
then I face a problem: It's ID is not the same as the project on the server. And the project's Id
property is read-only, so I can't update it.
I tried opening the project file, updating the Guid
attribute on the root element...
... and then reloading the project - here's the code I used...
private static void UpdateProjectId(FileBasedProject project, Guid newId, Reporter reporter)
{
const string projectFileExtension = ".sdlproj";
const string projectIdAttributeName = "Guid";
var projectInfo = project.GetProjectInfo();
var path = Path.Combine(projectInfo.LocalProjectFolder, $"{projectInfo.Name}{projectFileExtension}");
XDocument xProjectFile;
using (var fs = new FileStream(path, FileMode.Open))
{
xProjectFile = XDocument.Load(fs, LoadOptions.PreserveWhitespace);
}
var attrGuid = xProjectFile.Document.Root.Attribute(projectIdAttributeName);
if (attrGuid != null)
{
attrGuid.Value = newId.ToString();
xProjectFile.Save(path);
}
project = new FileBasedProject(path);
}
However, when I call project.GetProjectInfo().Id
after calling new FileBasedProject(path)
I still see the previous Guid
value - even though I can verify that the physical file does now have the new value.
So I took another look at the API reference and saw this method...
Perhaps that id
variable will allow me to specify the ID of the empty project?
Unfortunately it returns a 500 (Internal Server Error)
, and I can't see anything recorded in the log files relating to this error.
So what should I do? I have a local project, a corresponding server-based project, but their IDs are different. How can I use the ID of the server-based project against the local project?
Generated Image Alt-Text
[edited by: Trados AI at 4:08 AM (GMT 0) on 5 Mar 2024]