Microsoft.VisualStudio.Project.NestedProjectNode.SaveItem C# (CSharp) Method

SaveItem() public method

Saves the hierarchy item to disk.
public SaveItem ( VSSAVEFLAGS dwSave, string silentSaveAsName, uint itemid, IntPtr punkDocData, int &pfCancelled ) : int
dwSave VSSAVEFLAGS Flags whose values are taken from the VSSAVEFLAGS enumeration.
silentSaveAsName string File name to be applied when dwSave is set to VSSAVE_SilentSave.
itemid uint Item identifier of the hierarchy item saved from VSITEMID.
punkDocData System.IntPtr Pointer to the IUnknown interface of the hierarchy item saved.
pfCancelled int TRUE if the save action was canceled.
return int
        public override int SaveItem(VSSAVEFLAGS dwSave, string silentSaveAsName, uint itemid, IntPtr punkDocData, out int pfCancelled)
        {
            // Don't ignore/unignore file changes
            // Use Advise/Unadvise to work around rename situations
            try
            {
                this.StopObservingNestedProjectFile();
                Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
                Debug.Assert(punkDocData != IntPtr.Zero, "docData intptr was zero");

                // Get an IPersistFileFormat object from docData object (we don't call release on punkDocData since did not increment its ref count)
                IPersistFileFormat persistFileFormat = Marshal.GetTypedObjectForIUnknown(punkDocData, typeof(IPersistFileFormat)) as IPersistFileFormat;
                Debug.Assert(persistFileFormat != null, "The docData object does not implement the IPersistFileFormat interface");

                IVsUIShell uiShell = this.GetService(typeof(SVsUIShell)) as IVsUIShell;
                string newName;
                ErrorHandler.ThrowOnFailure(uiShell.SaveDocDataToFile(dwSave, persistFileFormat, silentSaveAsName, out newName, out pfCancelled));

                // When supported do a rename of the nested project here
            }
            finally
            {
                // Succeeded or not we must hook to the file change events
                // Don't ignore/unignore file changes
                // Use Advise/Unadvise to work around rename situations
                this.ObserveNestedProjectFile();
            }

            return VSConstants.S_OK;
        }