static void FileServiceFileRemoved(object sender, FileEventArgs e) { if (OpenSolution == null) { return; } string fileName = e.FileName; foreach (ISolutionFolderContainer container in OpenSolution.SolutionFolderContainers) { for (int i = 0; i < container.SolutionItems.Items.Count;) { SolutionItem item = container.SolutionItems.Items[i]; if (FileUtility.IsBaseDirectory(fileName, Path.Combine(OpenSolution.Directory, item.Name))) { container.SolutionItems.Items.RemoveAt(i); } else { ++i; } } } foreach (IProject project in OpenSolution.Projects) { if (FileUtility.IsBaseDirectory(project.Directory, fileName)) { IProjectItemListProvider provider = project as IProjectItemListProvider; if (provider != null) { foreach (ProjectItem item in Linq.ToArray(provider.Items)) { if (FileUtility.IsBaseDirectory(fileName, item.FileName)) { provider.RemoveProjectItem(item); OnProjectItemRemoved(new ProjectItemEventArgs(project, item)); } } } } } }
/// <summary> /// Removes a project item from the project, raising the ProjectItemRemoved event. /// Make sure you call project.Save() after removing items! /// No action (not even raising the event) is taken when the item was already removed form the project. /// </summary> public static void RemoveProjectItem(IProject project, ProjectItem item) { if (project == null) { throw new ArgumentNullException("project"); } if (item == null) { throw new ArgumentNullException("item"); } IProjectItemListProvider provider = project as IProjectItemListProvider; if (provider != null) { if (provider.RemoveProjectItem(item)) { OnProjectItemRemoved(new ProjectItemEventArgs(project, item)); } } }