Question

I'm new here..

Question:

Can you have an external settings file and read info from that in visual basic .net 4.0 using sharpdevelop?

Thanks for answers.

Was it helpful?

Solution

By config file I assume you mean the app.config file.

SharpDevelop supports both the old style of using the ConfigurationManager to get values from the appSettings section of your app.config:

<appSettings>
    <add key="PageSize" value="10" />
</appSettings>

Dim PageSize As Integer =
    Configuration.ConfigurationManager.AppSettings("PageSize")

It also supports the newer style of using a Settings file, which adds a custom section to your app.config and a generated VB.NET class.

<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="WindowsApplication1.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<userSettings>
    <WindowsApplication1.My.MySettings>
        <setting name="PageSize" serializeAs="String">
            <value>0</value>
        </setting>
    </WindowsApplication1.My.MySettings>
</userSettings>

My.Settings.Default.PageSize

The main difference between SharpDevelop and Visual Studio is that you will have to create the My Project folder structure and set the namespace to My on your .settings file via the file properties. Visual Studio will create the .settings file when you create a new project which makes it a bit easier to get started.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top