Share via


IVsApplicationConfiguration.QueryEditConfiguration Method

Determines if a configuration file can be modified.

Namespace:  Microsoft.VisualStudio.ManagedInterfaces9
Assembly:  Microsoft.VisualStudio.ManagedInterfaces.WCF (in Microsoft.VisualStudio.ManagedInterfaces.WCF.dll)

Syntax

'Declaration
Function QueryEditConfiguration As Boolean
bool QueryEditConfiguration()
bool QueryEditConfiguration()
abstract QueryEditConfiguration : unit -> bool 
function QueryEditConfiguration() : boolean

Return Value

Type: System.Boolean
true if the configuration file can be modified; otherwise false.

Remarks

The QueryEditConfiguration method calls the QueryEditFiles method to determine whether the configuration file can be edited. If the file does not exist, a default configuration file (if at the root level of the project) or an empty configuration file will be created.

Note

If the project is under source control, this action will cause the project file to be checked out and the project to be reloaded.

If the method results in a configuration file being added to the project, any previously returned configuration object is rendered invalid. Clients that have registered for a handler for the ConfigurationChanged event will be notified that the file has been added.

Examples

The following code example demonstrates how to use the QueryEditConfiguration method to determine whether a configuration file can be edited.

/// Make sure that our custom WSDL importer extension is registered in /// the Metadata section of the configuration file for the current 
/// project hierarchy and serviceProvider that gives access to required 
/// services.
private static void EnsureCustomWsdlImporterRegistered
 (IVsHierarchy hierarchy, IServiceProvider serviceProvider)
{
    /// The IVsApplicationConfigurationManager service returns a 
    /// System.Configuration.Configuration object corresponding to 
    /// the given project's app.config or web.config file.
    IVsApplicationConfigurationManager cfgMgr = 
 serviceProvider.GetService(typeof(IVsApplicationConfigurationManager))
 as IVsApplicationConfigurationManager;
    // Return the current application's configuration file by using 
    // the IVsApplicationConfiguration APIs. Make sure that the 
    // instance that is returned is disposed of correctly in order 
    // to clean up any event hooks or docdatas.
    using (IVsApplicationConfiguration appConfig = configManager.GetApplicationConfiguration(vsHierarchy, (uint)VSConstants.VSITEMID.Root))
{
    if (appConfig. QueryEditConfiguration())
    {
        System.Configuration.Configuration config = appConfig. LoadConfiguration();
        config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("ThisIs", "MyConnectionString"));
        config.Save();
    }
}


        // Check the file out from Source Code Control if it 
        // exists.
        appCfg.QueryEditConfiguration();

        /// After a System.Configuration.Configuration object
        /// exists, use the"normal" .NET Framework configuration
        /// APIs to return the sections that you want to modify.
        ServiceModelSectionGroup sg = 
 ServiceModelSectionGroup.GetSectionGroup(cfg);
        Type importerType = typeof(BindingPickerWsdlImportExtension);
        if (!IsWsdlImporterRegistered(sg, importerType))
        {
            // If our custom WSDL importer is not registered, add 
            // it to the application's configuration file.
            sg.Client.Metadata.WsdlImporters.Add(new 
 WsdlImporterElement(importerType));
            cfg.Save();
        }
    }
}

.NET Framework Security

See Also

Reference

IVsApplicationConfiguration Interface

Microsoft.VisualStudio.ManagedInterfaces9 Namespace