Compartilhar via


IVsQueryEditQuerySave2.QuerySaveFile Method

Definition

Notifies the environment that a file is about to be saved.

public:
 int QuerySaveFile(System::String ^ pszMkDocument, System::UInt32 rgf, cli::array <Microsoft::VisualStudio::Shell::Interop::VSQEQS_FILE_ATTRIBUTE_DATA> ^ pFileInfo, [Runtime::InteropServices::Out] System::UInt32 % pdwQSResult);
int QuerySaveFile(std::wstring const & pszMkDocument, unsigned int rgf, std::Array <Microsoft::VisualStudio::Shell::Interop::VSQEQS_FILE_ATTRIBUTE_DATA> const & pFileInfo, [Runtime::InteropServices::Out] unsigned int & pdwQSResult);
public int QuerySaveFile (string pszMkDocument, uint rgf, Microsoft.VisualStudio.Shell.Interop.VSQEQS_FILE_ATTRIBUTE_DATA[] pFileInfo, out uint pdwQSResult);
abstract member QuerySaveFile : string * uint32 * Microsoft.VisualStudio.Shell.Interop.VSQEQS_FILE_ATTRIBUTE_DATA[] * uint32 -> int
Public Function QuerySaveFile (pszMkDocument As String, rgf As UInteger, pFileInfo As VSQEQS_FILE_ATTRIBUTE_DATA(), ByRef pdwQSResult As UInteger) As Integer

Parameters

pszMkDocument
String

[in] Path to the file (document to be saved) on the disk.

rgf
UInt32

[in] Flags whose values for valid file attributes are taken from the tagVSQEQSFlags enumeration. The default value is zero.

pFileInfo
VSQEQS_FILE_ATTRIBUTE_DATA[]

[in] Values taken from the VSQEQS_FILE_ATTRIBUTE_DATA structure containing information about the file attributes. Can be null; is ignored if rgf is 0.

pdwQSResult
UInt32

[out] Pointer to a value taken from the tagVSQuerySaveResult enumeration.

Returns

If the method fails, it returns an error code.If it succeeds, it returns: QSR_SaveOK Save the file. The file should not be read-only at this point. QSR_ForceSaveAs

          QuerySaveFile has not put up a Save As dialog box, but either it is quietly telling you to do so, or the user has been prompted and has selected Save As. If you are editing a conventional file, you are encouraged to call the <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.IVsUIShell.GetSaveFileNameViaDlg(Microsoft.VisualStudio.Shell.Interop.VSSAVEFILENAMEW[])"></xref> method in the <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.IVsUIShell"></xref> interface at this point. 
          <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_NoSave_UserCanceled"></xref>
        The user was notified that the file is read-only and has elected either to not save or to cancel the operation. The choice depends on the <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.IVsQueryEditQuerySave2.BeginQuerySaveBatch"></xref> / <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.IVsQueryEditQuerySave2.EndQuerySaveBatch"></xref> methods. The results for <code data-dev-comment-type="paramref">*pdwQSResult</code> are:Proceed with save (<xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_SaveOK"></xref>).Do not save (<xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_NoSave_Continue"></xref>).Save as (<xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_ForceSaveAs"></xref>).Cancel Save (<xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_NoSave_UserCanceled"></xref> or <xref data-throw-if-not-resolved="true" uid="Microsoft.VisualStudio.Shell.Interop.tagVSQuerySaveResult.QSR_NoSave_Cancel"></xref>).

Remarks

COM Signature

From ivsqueryeditquerysave2.idl

HRESULT QuerySaveFile(  
   [in] LPCOLESTR pszMkDocument,  
   [in] VSQEQSFlags rgf,  
   [in] const VSQEQS_FILE_ATTRIBUTE_DATA *pFileInfo,  
   [out, retval] VSQuerySaveResult *pdwQSResult  
);  

Before a project or editor saves a file, it must call this method or the QuerySaveFiles method. For project files, these calls are completed automatically by the solution, which knows when to save a project file. Editors are responsible for making these calls unless the editor implementation of IVsPersistDocData2 uses the helper function SaveDocDataToFile method. If your editor implements IVsPersistDocData2 in this way, then the call to QuerySaveFile or QuerySaveFiles is made for you.

Call this method before saving anything to disk. It will handle read-only and checked-in files in a uniform, shared way.

This method may need to issue a checkout command to ensure that the file is writable (for example, if the file was edited in memory). For a source control package that provides for the "checkout local version" option, this is a safe operation. For a source control package that does not, the checkout operation cannot be completed without data loss. In this case, Save As is the only option.

Applies to