Monthly Archives: October 2011

Silverlight – C# – How to set a XAML element’s style from code behind

XAMLelementName.Style = Application.Current.Resources["Style"] as Style; // If your style is defined in App.xaml Application.Resources section XAMLelementName.Style = this.Resources[StyleKey] as Style; // if your style is defined in Page.XAML UserControl.Resources section XAMLelementName.Style = button.Resources[StyleKey] as Style; // if your style is … Continue reading

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 2 Comments

Silverlight – C# – How to set XAML element’s margin from code behind

XAMLelementName.Margin = new Thickness(1, 2, 3, 4); // OR, if you need uniform thickness XAMLelementName.Margin = new Thickness(5);

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 3 Comments

File upload run time error – Maximum request length exceeded

If you are getting this error while uploading file on the server, add following configuration setting in web.config- <configuration> <system.web> <httpRuntime maxRequestLength=”102400″ executionTimeout=”1200″ /> <!– 102400 in KB is 100 MB, 1200 is in seconds–> </system.web> </configuration>

Posted in ASP.NET, Knowledge Sharing | Leave a comment

Download a file from server or open a web address in a pop-up window from Silverlight client

You can use HyperlinkButton control to do this. Example- <HyperlinkButton Name=”hplTemplete” Content=”Open Google in New Window” NavigateUri=”http://www.google.com” TargetName=”_blank” /> In case you need to set its NavigateUri from code behind, use following code- hplTemplete.NavigateUri =new Uri(“http://www.google.com”);

Posted in C#, Knowledge Sharing, Silverlight | 4 Comments

File Upload from Silverlight Client – A Generic http Handler to Upload File

From Silverlight client, you can upload files on server. For this you need a httphandler. Following is the code for the httphandler- using System; using System.Web; using System.IO; using System.Configuration; namespace WebProject.Web { public class FileUpload : IHttpHandler { public … Continue reading

Posted in C#, Knowledge Sharing, Silverlight | Leave a comment

Silverlight – Run Time Exception – Value does not fall within the expected range

If you are getting this error, you need to make sure that all xaml elements have unique names. Consider the following code snippets- for (int Count = 0; Count < StackPanel.Children.Count; Count++) { Chart ch = (Chart)StackPanel.Children[Count]; AnotherStackPanel.Children.Add(ch); } The … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 2 Comments

How to associate XAP extension with Shell Zip application

To make it easier to unzip the XAP file of your application, you can associate the XAP extention with the Shell Zip application. To do this, run following command on command prompt- cmd /c assoc .xap=CompressedFolder

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 4 Comments

Silverlight – What is inside a XAP file

XAP = dll(s) + AppManifest.xaml A XAP file is a combination of required DLLs and a AppManifest.xaml file compressed together and ZIP extention is changes to XAP. If you change the XAP extention back to ZIP, extract this ZIP file, … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 5 Comments

Creating Word document in Silverlight

Creating a Word document programatically is a frequent client requirement. In Silverlight, if you are creating Out-Of-Browser application, you have option to use Office Interop. But if you need to create a Word, Excel or PDF report in Silverlight browser … Continue reading

Posted in Silverlight | 5 Comments

What is the benefits of using C# Properties over Fields

Many benefits- 1. Properties are used for data binding; Fields aren’t. 2. Encapsulation can be achieved with Properties, not with Fields. An example below- public int Order { get { return m_order; } set { //Encapsulation goes here // Put … Continue reading

Posted in C# | 3 Comments