How may I delete files from a FileBasedProject?

Hi everyone!

 

Could someone please advise me on how I may delete files from a project?

I have added files to the project like this:

 

FileBasedProject project= new FileBasedProject(new ProjectInfo() { Name = "Dummy", SourceLanguage = new Language("en-US"), TargetLanguages = new[] { new Language("de-DE") }, LocalProjectFolder = projectFolder });

project.AddFolderWithFiles(@"C:\FolderWithSourceFiles", false);

 

How may I delete the source files in C:\FolderWithSourceFiles from the FileBasedProject?

Thank you!

Parents
  • If you wish to remove the files from the project, the API does not provide a method for that.

    You can delete files using System.IO like Florentina suggests but you also need to tell Studio / the filebased project about it. You can achieve that by manipulating the project XML itself.

    But be careful: before you do that, you first need to unload it from Studio. So what you would do is

    var controller = SdlTradosStudio.Application.GetController<ProjectsController>();
    var pPath = project.FilePath;
    controller.Close(project);

    Then load sdlproj file as XmlDocument() or XDocument,

    var projectXML = new XmlDocument();
    projectXML.Load(pPath);

    carefully remove the respective nodes from the ProjectFiles node (make sure to remove both source and target language files), save, reopen:

    projectXML.Save(pPath);
    project = new FileBasedProject(pPath);
    controller.Open(project);

     

    Regards,
    Andreas

Reply
  • If you wish to remove the files from the project, the API does not provide a method for that.

    You can delete files using System.IO like Florentina suggests but you also need to tell Studio / the filebased project about it. You can achieve that by manipulating the project XML itself.

    But be careful: before you do that, you first need to unload it from Studio. So what you would do is

    var controller = SdlTradosStudio.Application.GetController<ProjectsController>();
    var pPath = project.FilePath;
    controller.Close(project);

    Then load sdlproj file as XmlDocument() or XDocument,

    var projectXML = new XmlDocument();
    projectXML.Load(pPath);

    carefully remove the respective nodes from the ProjectFiles node (make sure to remove both source and target language files), save, reopen:

    projectXML.Save(pPath);
    project = new FileBasedProject(pPath);
    controller.Open(project);

     

    Regards,
    Andreas

Children
No Data