Asp.Net jQuery like Closest()

Here is a very simple .Closest() function like the jquery one. public static class ControlExtensions { public static Control Closest(this Control control, Type type ){ Control closest = null; Control parent = control.Parent; while(closest == null && parent != null){ if(parent.GetType().ToString() == type.ToString()){ return parent; } parent = parent.Parent; } return null; } }

UAD6 – Physical path to virtual

Simple util to take a physical path and gets its virtual equivalent. public static string PhysicalPathToVirtual(string path) { if (HttpContext.Current != null && !String.IsNullOrEmpty(path)) { return "/" + path.Replace(HttpContext.Current.Server.MapPath("/"), "").Replace(@"\", "/"); } else return null; } public static string PhysicalPathToVirtual(HttpContext…Continue Reading →

Jayrock – Converting to string and back

I always seem to forget how to do this so I’m just leaving a note for myself 🙂 To convert to string: Jayrock.Json.Conversion.JsonConvert.ExportToString([object]); To convert back again ([object])Jayrock.Json.Conversion.JsonConvert.Import(typeof([object]), result);