MsSql: How to enable clr (to run c# / vb code in SQL)

by Pieter Brinkman 26. June 2008 08:03

Execute the next query to enable CLR.  

-- Turn advanced options on

EXEC sp_configure 'show advanced options' , '1';

go

reconfigure;

go

EXEC sp_configure 'clr enabled' , '1'

go

reconfigure;

-- Turn advanced options back off

EXEC sp_configure 'show advanced options' , '0';

go

More info about CLR on Microsoft MSDN.

Tags: , ,
Categories: MSSQL

Regular Expressions and Matchhandlers

by Mark 26. June 2008 04:46

For a project I need te get the email adresses out of a string with all kinds of text in it. After a lot of trying I found the matchhandler method. It is quite easy, you just need to adjust the Replace command and add a MatchEvaluator. Then you can use the matchhandler to do anything with the right string. In this case I´m adding it to a generic list.

Regex.Replace(source, @"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", new MatchEvaluator(MatchHandler));

And add the string to the generic list.

private string MatchHandler(Match m)

{

     col.Add(m.Value);

     return m.Value;

}

Tags:
Categories: ASP.Net

Asp.Net AJAX controltoolkit javascript funtions

by Pieter Brinkman 25. June 2008 10:24

I've search them all up for a 1000 times. Now I'm going to write them down as reference. This post will grow in the next few months.

Remember do not forget to set the behaviorId of the control. 

References:

CollapsiblePanelExtender
Expand:

  • $find('BehaviorId')._doOpen();

Collapse:

  • $find('BehaviorId')._doClose();
  • $find('BehaviorId').collapsePanel();

ModalPopupExtender
Show popup:

  • $find('BehaviorId').show();

Hide popup:

  • $find('BehaviorId').hide(); 
Categories: AJAX | Controls | JavaScript

String Extension Method: IsGuid()

by Pieter Brinkman 23. June 2008 08:46

I wrote an extension method for the string type. With this method you can check if an string is an Guid. The method returns a Bool.

public static class StringExtensions
{
  public static bool IsGuid(this string input)
  {
    Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
    bool isValid = false;
    if (input != null)
    {
      if (isGuid.IsMatch(input))
      {
        isValid = true;
      }
    }
  return isValid;
  }
}

If you're wondering I didn't wrote the Regex myself :-) (but it works)

This brute-force method is mutch faster (thanks to Arjan and Tag for the comments):

public static bool IsGuid(this string input)
{
try
{
new Guid(input);
return true;
}
catch (ArgumentNullException) {}
catch (FormatException) {}
catch (OverflowException) {}
return false;
}

 

A good example how extension methods can make some things easier. 

Hope it helps!

Categories: ASP.Net

Using Session with a Web Handler File (ashx)

by Pieter Brinkman 11. June 2008 08:33

In on of our project we use ASHX file to dynamicly generate stylesheets depending on the user. An problem occurred when the userdata was loaded from the Session. The Session object was NULL.

After searching the internet I found the solution for this problem. You need to implement the folowing interfaces on the ASHX;  IRequiresSessionState and IReadOnlySessionState. See example below.

public class Style : IHttpHandler, IRequiresSessionState, IReadOnlySessionState {}

 

Categories: ASP.Net