in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

Kyle Kelin on .Net

August 2008 - Posts

  • Can You Do TDD on a SharePoint Project?

  • How Come My Silverlight Application Won’t Load?

    So you have written your first Silverlight application and deployed it to IIS but when you hit the page nothing happens. No error, nothing. You are just sitting there staring at a blank web page. Chances are you haven't registered the Silverlight MIME type yet. Go into IIS and register the following MIME type: .xap to application/x-silverlight-app. I will leave it up to you to Google the details of how to do that.

  • DateTime serialization issue with .NET and JSON

    I was writing some client code that calls some .NET Web Services and getting a strange error. I wanted to post this just to warn people to watch out for the DateTime object and null values. I have two web services, one gets an array of Entity objects and the other takes an array of Entity objects. The array is being serialized into JSON. The get web method worked fine but when I tried to pass the array to the save web method I got the following error:

     

    System.InvalidOperationException: SaveUserFavorites Web Service method name is not valid.

       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()

       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest

     request, HttpResponse response, Boolean& abortProcessing)

     

    Now what sucks about this error is it is pretty generic. It pretty much means that the Ajax class cannot find a web service method that matches. So first I double checked my method names and parameters and no problem there. I'm going to fast forward through my debugging problems because this error took me awhile. The issue is one of my properties on my Entity object was a DateTime. It seems that when I was getting the JOSN array .NET serializes it wrong and then cannot read it. I really didn't need the property so I commented it out. But I did some additional research for this post and found that null is not a valid JSON value so the parser failed.

    More info - http://west-wind.net/weblog/posts/398970.aspx

    Tip: Firebug is critical in debugging ajax calls.

     

     

    Posted Aug 22 2008, 11:31 PM by KyleKelin with no comments
    Filed under: ,
  • Searching and Comma-Delimited Strings in SQL

    I recently needed to write a stored procedure that would take a search string from a web form and search three columns: name, description, and keywords. The keywords column and the input string can both be comma delimited. The key to the sproc is going to be the SQL IN operator. The IN operator can be used in a where clause to filter based on a list like so:

    Where

        id IN (1,4,6,10,13)

     

    So what I needed was:

     

    Where

        id IN (@searchString)

     

     

    But you can't do that so I needed to write a split function to split out @searchString. Note: I think there maybe be a split function in SQL Server 2005/2008 but I was using SQL Express.

     

    Here is the final result:

    ALTER FUNCTION dbo.Split

    (

        @List nvarchar(2000),

        @SplitOn nvarchar(5)

    )

    RETURNS @RtnValue table

    (

            

        Id int identity(1,1),

        Value nvarchar(100)

    )

    AS

    BEGIN

     

    While (Charindex(@SplitOn,@List)>0)

    Begin

     

    Insert Into @RtnValue (value)

    Select

    Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))

     

    Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))

    End

     

    Insert Into @RtnValue (Value)

    Select Value = ltrim(rtrim(@List))

     

    Return

    END

    -------------------------------------------------------------------------------------

    ALTER PROCEDURE SearchApplications

        (

        @searchWord varchar(100)

     

        )

    AS

    SELECT ID, [Name], Description FROM Applications

     

    WHERE

    [Keywords] IN (Select Value from dbo.Split(@searchWord,',')) or

    [Name] IN (Select Value from dbo.Split(@searchWord,',')) or

    [Name] = @searchWord or

    [Description] IN (Select Value from dbo.Split(@searchWord,',')) or

    [Description] = @searchWord

     

2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems