This is a migrated thread and some comments may be shown as answers.

Using AppSettings values

3 Answers 172 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 30 Jan 2011, 11:56 AM
Is there a way to use values from the main web app settings file.

I have a web and separate class files for the reporting, the web imports the reporting class.

I want to dynamicly change the logo on a report base on the value in the web appsettings.

This is how I would do it in the web:

Me

 

.imgLogo.Value = ConfigurationManager.AppSettings("TrustLogo")

But this currently doesn't work from the reporting class.

Andy

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 02 Feb 2011, 04:18 PM
Hello Andy Green,

Telerik Reporting is a standard .NET class and you can easily access the AppSettings within an User Function to retrieve an Image and set the PictureBox.Value with Binding to GetImage(). Check out the following code snippet:

Public Shared Function GetImage() As Image
    Dim filename As String = ConfigurationManager.AppSettings("TrustLogo")
    Return Bitmap.FromFile(filename)
End Function

Best wishes,
Peter
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
John
Top achievements
Rank 1
answered on 10 Mar 2011, 02:15 PM
I have a similar problem and cannot get it to work in the Silverlight Reporting. I have added the following into my Reports class library app.config file

<appSettings>
    <add key="MyKey" value="MyValue"/>
  </appSettings>

I then created a user function with the following code

public static string GetAppSettingValue()
{
    string returnValue = "";
            
    try
    {
        returnValue = ConfigurationManager.AppSettings["MyKey"].ToString();
    }
    catch (Exception ex) { returnValue = ex.Message; }


    return returnValue;
}

I then tested it in a report by returning the value of my user function to a textbox but all I get is the error "Object Reference not set to an instance of an object"

Can you show me an example of reports retrieving the value from the config file?

Thanks,
John

        
0
Andy Green
Top achievements
Rank 2
answered on 10 Mar 2011, 03:00 PM
This is what I have.

Using best practice I have a separate project for my reports. In the code behind for the report I have

 

Public Sub New()

 

 

InitializeComponent()

 

 

Me.imgLogo.Value = ConfigurationManager.AppSettings("Logo")

 

 

 

End Sub

Where imgLogo is the image control on y report

Andy

 

Tags
General Discussions
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Peter
Telerik team
John
Top achievements
Rank 1
Andy Green
Top achievements
Rank 2
Share this question
or