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!

2 Replies Latest Replies: 16 May 2018 12:39 PM by Florentina Caputa
  • Hello

    Have you tried to delete the file using System.IO.File.Delete(string filePath)? I have used System.IO.File to move a project file from a location to another,because I didn't found a method provided by the Studio API's, so it should be possible to delete it like that.

    With kind regards,
    Florentina Caputa

  • 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


Related