all things Sitecore related


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 »

LINQ: Creating a if statement in Linq query

By on July 30, 2009 in ASP.Net, linq with 0 Comments

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 […]

Continue Reading »

Linq to Xml: Generate Google Sitemap with sitemap-protocol

By on July 8, 2009 in ASP.Net, Google, linq, XML with 1 Comment

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>{  "",  "",  "",  "" }; //Create namespace for sitemap-protocol XNamespace xmlNS = ""; XDocument xmlDoc =  new XDocument(   new XDeclaration("1.0", "UTF-8", null),   new XElement(xmlNS + "urlset",    from blogPostUrl in […]

Continue Reading »

Linq Casting: ToDictionary()

By on June 23, 2009 in linq with 0 Comments

In this post I will give an example how to cast a GenericList to Dictionary. This example will use the following Blogger class. public class Blogger {  public string FirstName { get; set; }  public string LastName { get; set; }  public int Age { get; set; }  public string Blog { get; set; } } The example […]

Continue Reading »

WCF webservice error with DBML objects

By on May 7, 2009 in ASP.Net, linq, Silverlight with 2 Comments

When deploying a WCF webservice for a Silverligh application I got the following error: An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior  contract: <a href=""></a> —-> System.Runtime.Serialization.InvalidDataContractException: Type 'Project.service.HU_BACH.ScPlacemark' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and […]

Continue Reading »

Linq to Sql: Retrieve properties from related data (LoadWith)

By on January 15, 2009 in ASP.Net, linq, SQL Server with 0 Comments

You have to specify which related-data you want to retrieve from a object so you can access them outside the Linq data-context. You can achieve this by using the LoadWith method of the DataLoadOptions Class. The LoadWith method accepts an lambda expression that specifies which object you want to retrieve. In the following example I […]

Continue Reading »

Convert XmlElement to XElement (Extension Method)

By on December 8, 2008 in linq, XML with 5 Comments

I was using some web-services that returned there values in an XmlElement. I needed to convert this XmlElement to something that I can use with LINQ. I didn't find good solutions on the internet. So I started building my own convert logic. After all kinds of solutions I ended up with creating an new XmlDocument, […]

Continue Reading »

Load rss (xml) with Linq to XML on medium trust hosting

By on November 26, 2008 in ASP.Net, linq with 0 Comments

For a new project I needed to implement show data from RSS. The site will be hosted on a shared hosting environment with medium trust. I load the rss with the following code: [code:c#] XElement rssFeed = XElement.Load("[REPLACE WITH URL TO RSS]"); var posts = from item in rssFeed.Descendants("item")                   select new                   {                        Title […]

Continue Reading »

Linq to Sql: Change connectionstring to load from Web.config

By on September 2, 2008 in ASP.Net, linq, SQL Server with 2 Comments
Linq to Sql: Change connectionstring to load from Web.config

Update 20 may 2009: New easy sollution Set the Connection -> Application Settings property True. This will generate a connection string in your app.config.   Copy this connection string to your web.config and your all set!   =================================================================  Old post:  If you want to use your connectionstring from the web.config with Linq to Sql (dbml) […]

Continue Reading »

Dynamic load where parameters for linqDatasource

By on April 21, 2008 in ASP.Net, C#, linq with 5 Comments

When using an Linq Datasource (linq to sql) for a datagrid (Gridview, ListView, etc) you don’t always want all rows from a table. To exclute data you can use the WhereParameters to add an where statement to your DataSource. You can do limited where statements with the Visual Studio Wizards. When you need more than a […]

Continue Reading »