all things Sitecore related

Tag: C#

Want to help your business user? Create a custom Macro

Want to help your business user? Create a custom Macro

When talking to business users (people that actually work with Sitecore on a day to day base) I created a small list of minor custom changes that would help the business users with there day to day work. One of the items on this list is the condition for User Profile fields, by default the […]

Continue Reading »

Design Patterns(C#): Basic example Strategy pattern

Design Patterns(C#): Basic example Strategy pattern

In this example I´m going to explane the strategy pattern. With this example you can do a calculation with two numbers (-/+) and expand the number of operators (/, *, etc.). First create a interface which defines the interface of the operator classes. For this example an operator can only calculate two values. //The interface […]

Continue Reading »

Asp.Net: keyboard sort items

By on September 24, 2010 in ASP.Net, C#, Javascript with 0 Comments
Asp.Net: keyboard sort items

As proof of concept I wanted to sort images in a Grid by keyboard. The sort logic needed to be implemented on the server. My solution for this problem is a combination of Javascript and C#. First add following html to you .aspx. Notice that the body tag has runat=”server” and a ID. <body<strong> runat="server" […]

Continue Reading »

C#: Get Parent Control with Generics

By on April 27, 2010 in ASP.Net, C#, Controls with 0 Comments
C#: Get Parent Control with Generics

I use the following method to return a parent control of a specific type. This method is recursive and uses generics. <br /> private Control GetParentControl<T1>(Control control)<br /> {<br /> if (control.Parent.GetType() == typeof(T1))<br /> {<br /> return control.Parent;<br /> }<br /> else<br /> {<br /> return GetParentControl<T1>(control.Parent);<br /> }<br /> }</p> <p>

Continue Reading »

MemoryStream to Byte Array (Byte[])

By on April 19, 2010 in ASP.Net, C# with 0 Comments

With the following code you can convert your MemoryStream to a Byte Array. //create new Bite Array byte[] biteArray = new byte[memoryStream.Length]; //Set pointer to the beginning of the stream memoryStream.Position = 0; //Read the entire stream memoryStream.Read(biteArray, 0, (int)memoryStream.Length);

Continue Reading »

C#: Remove line from textfile

By on January 26, 2010 in ASP.Net, C#, linq with 0 Comments

With the following code you can remove a line from a textfile (web.config). If the string is within a line the line will be removed. string configFile = @"C:devweb.config"; List<string> lineList = File.ReadAllLines(configFile).ToList(); lineList = lineList.Where(x => x.IndexOf("<!–") <= 0).ToList(); File.WriteAllLines(configFile, lineList.ToArray());

Continue Reading »

Top