private void MoveFilesForDeferredSave(HierarchyNode node, string basePath, string baseNewPath) { if (node != null) { for (var child = node.FirstChild; child != null; child = child.NextSibling) { bool isOpen, isDirty, isOpenedByUs; uint docCookie; IVsPersistDocData persist; var docMgr = child.GetDocumentManager(); if (docMgr != null) { docMgr.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out persist); int cancelled; if (isDirty) { child.SaveItem(VSSAVEFLAGS.VSSAVE_Save, null, docCookie, IntPtr.Zero, out cancelled); } FileNode fn = child as FileNode; if (fn != null) { string newLoc = GetNewFilePathForDeferredSave(basePath, baseNewPath, child.Url); // make sure the directory is there Directory.CreateDirectory(Path.GetDirectoryName(newLoc)); fn.RenameDocument(child.Url, newLoc); } FolderNode folder = child as FolderNode; if (folder != null) { folder.VirtualNodeName = GetNewFilePathForDeferredSave(basePath, baseNewPath, child.Url); } } MoveFilesForDeferredSave(child, basePath, baseNewPath); } } }