user1141787
user1141787

Reputation: 21

How can we read app setting value from web.config in lightswitch desktop application

Please provide me with sample code which read web.config app settings value in a lightswitch desktop application which is been deployed in a webserver.

In Silverlight we can have initparams in the object tag that can be retrieved through the app.xaml startup event arguments.But in lightswitch could not find any startup method with arguments.

Help highly appreciated

Upvotes: 1

Views: 1378

Answers (2)

Raja Afrika
Raja Afrika

Reputation: 1

Silverlight applications can use Isolated Storage to mimic global variables. Here is a code example of using global variables in LightSwitch 2015:

Bottom Line: You can use Isloated storage like a global variable that you set at application initilization and then call from your event code.

Private appSettings As IsolatedStorageSettings  =IsolatedStorageSettings.SiteSettings

Private Sub MyScreen_Activated() Sub SearchClients_Execute()
 ' Write your code here.
appSettings.Remove("ApplicationID")
appSettings.Add("ApplicationID", "MyGlobalValue")
End Sub

Private Sub SearchPatients_Execute()
Dim ApplicationID As String = appSettings("ApplicationID")
End Sub

There are more details on using isolated storage as a Global Variable Cache here http://webmaster.rajaafrika.com/Blog/?pid=542&bid=14&d=Tech+Blog.

Upvotes: 0

dotNet Decoder
dotNet Decoder

Reputation: 531

Even I was looking for an answer and I didnt find one. I created a RIA service with POCO and read all config values from AppSettings. Following code may help you.

public class UserConfiguration
{
    [Key]
    public string ConfigKey { get; set; }
    public string ConfigValue { get; set; }


    public List<UserConfiguration> GetUserConfigurations()
    {
        return _getUserConfigurations();
    }

    private List<UserConfiguration> _getUserConfigurations()
    {
        var listOfConfigs = new List<UserConfiguration>();
        var allConfigs = ConfigurationManager.AppSettings;

        for (int i = 0; i < allConfigs.Count; i++)
        {
            var userConfig = new UserConfiguration();
            userConfig.ConfigKey = allConfigs.GetKey(i);
            userConfig.ConfigValue = allConfigs[i];
            listOfConfigs.Add(userConfig);
        }
        return listOfConfigs;
    }
}

And In Domain Service

[Query(IsDefault = true)]
    public IQueryable<UserConfiguration> GetUserConfigurations()
    {
        var userConfings = new UserConfiguration();
        return userConfings.GetUserConfigurations().AsQueryable();
    }

Upvotes: 1

Related Questions