Hi,
is there any way to delete a project file programatically? I have not found any related method in the API.
Thanks,
Tamas
Hi,
is there any way to delete a project file programatically? I have not found any related method in the API.
Thanks,
Tamas
Hi Tamas,
You can load the project using FileBasedProject class and then call Delete() method.
Romulus Crisan | Translation Productivity Development Manager | SDL | (twitter) @cromica_82 | (blog) http://www.romuluscrisan.com/
Hi,
Sorry, I was not clear, I mean to delete a ProjectFile (a translatable or a reference file), not the sdlproj file itself.
Tamas
Hi,
Up on this one.
I found a workaround, but it's definitely not straightforward: you delete the LanguageFile node using the Id (I used XPathDocument, and the XPath expression "//LanguageFile[@Guid='" + TargetLanguageFile.Id + "']", then physically deleting said file from the disk using System.IO.File.Delete(TargetLanguageFile.LocalFilePath);
Whole code looks like this:
XmlDocument pfile = new XmlDocument();
pfile.Load(project.FilePath);
XPathNavigator pnav = pfile.CreateNavigator();
XPathExpression xpr = pnav.Compile(@"//LanguageFile[@Guid='" + tfiles[incr].Id + "']");
XPathNodeIterator iterator = pnav.Select(xpr);
foreach (XPathNavigator node in pnav.Select(xpr))
{
node.DeleteSelf();
}
pfile.Save(project.FilePath);
File.Delete(tfiles[incr].LocalFilePath);
Loop as you want to retrieve the file, it's entirely up to you. Note: "project" is the FileBasedProject, and tfiles[] is the project.TargetLanguageFiles().
Careful though, as you will need to reload your FileBasedProject and not use any existing instance (everything is kept in memory, so changes made using XMLDocument will be overwritten.
But it would be great if we could have a simple method to delete files/folders, or restrict CopyToTargetLanguages to specified languages only...
Thanks,
Sylvain
Thanks Sylvain,
in the meantime I came to the same solution, this really works.
Regards,
Tamas