[HowTo] LINQ filter : Ignore accented letters (Diacritics) in string comparison ?
Here is a small extension method that will do the job (Warning : do not use for Linq To Sql): public static string RemoveDiacritics(this string text) { string formD = text.Normalize(NormalizationForm.FormD); StringBuilder sb = new StringBuilder(); foreach (char ch in formD) { UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(ch); if (uc != UnicodeCategory.NonSpacingMark) { sb.Append(ch); } } return […]
Could not load file or assembly ‘xxx.yyy’ or one of its dependencies…
Annoying message … if any… Could not load file or assembly ‘xxx.yyy’ or one of its dependencies. An attempt was made to load a program with an incorrect format. or in French : Impossible de charger le fichier ou l’assembly ‘xxx.yyy’ ou une de ses dépendances. Tentative de chargement d’un programme de format incorrect. Problem […]
[HowTo] Raising Custom Events in C#
First you need to declare an event in the class that’s going to raise the event. This is just like declaring a normal variable: public event EventHandler MyEvent; Then you need a method that’s going to be called to raise the event. This goes into the same class that you just declared the event in. […]
[HowTo] Find the Component Container
[Browsable(true)] [Category(“Data”), Description(“The parent container, usually the form, that contains the controls on which the ErrorProvider can display error icons “), Localizable(true)] public ContainerControl ContainerControl { get { return _containerControl; } set { _containerControl = value; } } public override ISite Site { get { return base.Site; } set { base.Site = value; if (value […]
[HowTo] C# Hide TitleBar on MDI Child windows when maximized
1) All childs WindowState must be set to Normal 2) Show() method must becalled rather than Focus() . 3) The Big One: Parent windows MainMenuStrip must be set (put something like this.MainMenuStrip = new MenuStrip(); in the mdi form_load event). Source
The type initialized for ‘SingletonCreator’ threw an exception or System.BadImageFormatException
You are using GreatMap.Net (Gmap.net) in visual studio and you eventually have one of those error messages : The type initialized for ‘SingletonCreator’ threw an exception System.BadImageFormatException Don’t worry there is a solution… The type initialized for ‘SingletonCreator’ threw an exception Simply add this useLegacyV2RuntimeActivationPolicy=”true” in your app.config file in the <Startup> tag in order […]
[HowTo] Write Excel file to web page (aspx)
Writing an Excel file to the response object in ASP.NET is quite easy… This piece of code works with most of the files type… string YourFilename = “test.xlsx”; string path = Server.MapPath(YourPath + YourFilename); Response.ClearContent(); Response.AddHeader(“content-disposition”, “attachement;filename=” + YourFilename); // Ouvrir avec MSExcel Response.ContentType = “application/ms-excel”; // MSWord // Response.ContentType = “application/msword”; // Text // […]
[HowTo] Define a constant globaly in C# (like DEBUG)
You can add the define compiler switch in your IDE. Open the project’s Property Pages dialog box. Click the Configuration Properties folder. Click the Build property page. Modify the Conditional Compilation Constants property
Handling Multiple Result (Shapes) from SPROCs
Handling Multiple Result Shapes from SPROCs [Function(Name = “spGetWebAccount”)] [ResultType(typeof(Client))] [ResultType(typeof(User))] [ResultType(typeof(UA_User))] public IMultipleResults spGetWebAccount(System.Nullable<Int64> ClientID, System.Nullable<Int64> UserID) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), ClientID, UserID); return (IMultipleResults)result.ReturnValue; } Source : http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
Exposing an event handler as a control property
You need to expose it as full-blown event, not as property. Page parser in ASP.NET is then able to wire syntax On=”handler_method_name” into your event as listener. #region Event Handlers public delegate void OnAddressSavedHandler(object sender, AddressEventArgs e); public class AddressEventArgs : EventArgs { public Int64 AddressID; public AddressEventArgs(){ } public AddressEventArgs(Int64 val) { AddressID = […]