tdatasource

I was really thrilled to see that Sitecore 7 will support coded datsources. This is a feature we already implemented at our company in earlier sitecore versions (kudos for the idea for my colleague and fellow MVP Remco van Toor). Coded datasources are very powerful and are frequently used in our company. For example in our latest project we use the sitecore enterprise ecommerce module. Customers are located in the ecommerce database but we had the need to render them as a More Info »

daily tip

With the Sitecore API it’s very easy to add items to the cache. You van use Sitecore.Caching.Cache to do the necessary operations. To add something to the cache you can use several overloads. Most of the time you want to add an expiration to the cached data. You have two different overloads to do this. Add(string key, object data, long dataLength, TimeSpan slidingExpiration) Add(string key, object data, long dataLength, DateTime absoluteExpiration) First method is to add a sliding expiration. The second method More Info »

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 for the strategies public interface ICalculateInterface { //define method int Calculate(int value1, int value2); } Next create the operators (strategies) Minus (which subtract value 2 from value More Info »

The test-team came to me with a problem involving connection errors while running webtests trough the company proxy. The webrequest needed to go to the webproxy including authentication. Visual Studion 2008 doesn’t support proxy authentication out of the box, but you can create a WebTestPlugin that does the authentication for every request. The following class inherits from WebTestPlugin and overrides the PreWebTest method. In the PreWebTest method it will authenticate the request with your credentials. public class LoadTestProxyAuthentication : WebTestPlugin {         More Info »

Asp.Net: keyboard sort items

sort_image

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" ID="bodyTag"</strong>> <form id="form1" runat="server"> <asp:Button runat="server" Text="Up" ID="UpButton" CommandArgument="up" oncommand="DownButton_Command" /> <br /> <asp:Button runat="server" Text="Left" ID="LeftButton" CommandArgument="left" oncommand="DownButton_Command" /> <asp:Button runat="server" Text="Right" ID="RightButton" oncommand="DownButton_Command" CommandArgument="right" /> More Info »

get parent control

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>

MemoryStream to Byte Array (Byte[])

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);

C#: Remove line from textfile

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());

When using the Datapager with a ListView I had the following problem. When clicking a paging button for the first time nothing happens.But when I click a button the second time, then the page from the first click loads. I search the internet for a solution and found that you need to add some code to the OnPagePropertiesChanging event of the list view to reload the DataPager. The following code is the solution to my problem. Including a fix that the data doesn’t get loaded More Info »

TypeMock: Mock Unittest examples

In this example I will show how to create a Unit Test with TypeMock. First I have created some basic dummy classes for the example public sealed class ServiceFactory {     public static ExpireDateService CreateExpireDateService()     {         ExpireDateService expireDateService = new ExpireDateService();         expireDateService.administration = new SqlAdministration("connectionstring");         return expireDateService;     } } /// <summary> /// SqlAdministrion creates connection and managed queries with SQL /// </summary> public class SqlAdministration {     private static DateTime LoadParameterPrivate()     {         return DateTime.Parse("01-01-1980");     More Info »

Asp.net: DateTime Eval String formatting

With the following code you can format a DateTime within a Databind. <%# DateTime.Parse(Eval("DateModified").ToString()).ToString("MM-dd-yyyy")%> 

When deploying a Silverlight application we ran into problems a WCF web-service, to find out what the problem was I wanted to invoke the method. Microsoft shipped an application for invoking methods from your Windows PC (WCFtestclient.exe). The following steps explain how to use WCFtestclient.exe. First startup Visual Studio 2008 Command Prompt. In the command prompt type wcftestclient, the application will startup. Now we need to add the Service. Click File and Add Service.   Add the URL to your service in the pop-up More Info »

A lot of times I need to check a statement within my LINQ-query and I wish there was a possibility of a IF statement within LINQ. The following code is the solution to my IF problem. I use a temporary variable (let isOlderThen30) to check if a statement is true. Then in my WHERE statement I use the temporary variable in a INFLINE IF. For this example I use my Blogger class with some data public class Blogger {  public string FirstName More Info »

In this example I will generate a XML site-map that complies with the sitemap-protocol XML schema. //create datasource List<string> blogPosts = new List<string>{  "http://blog.newguid.net/mypost1.aspx",  "http://blog.newguid.net/mypost_about_Net.aspx",  "http://blog.newguid.net/morePosts.aspx",  "http://blog.newguid.net/andEvenMorePosts.aspx" }; //Create namespace for sitemap-protocol XNamespace xmlNS = "http://www.sitemaps.org/schemas/sitemap/0.9"; XDocument xmlDoc =  new XDocument(   new XDeclaration("1.0", "UTF-8", null),   new XElement(xmlNS + "urlset",    from blogPostUrl in blogPosts    select     new XElement(xmlNS + "url",     new XElement(xmlNS + "loc", blogPostUrl))     )); //Show output Response.Write(xmlDoc); This example will give the following output: <urlset More Info »

Add meta-data dynamically to your page by adding a HtmlMeta control to your Header. In this example I dynamically add a keyword string to the page. string keyWords = "metatags, html, dynamic, generate"; HtmlMeta keywords = new HtmlMeta(); keywords.Name = "keywords"; keywords.Content = keyWords; Page.Header.Controls.Add(keywords);  You can do the same for other meta-data like description.