I've seen a few pages on the net regarding this, but unfortunately the sample code is in C#. I can't make sense of most of it (and/or run it through a code translator) but I still need help making it work in VB.
My custom function is:
Public Shared Function GetFriendlyTitle(Title As String) As String
Dim ConvertedTitle As String = ""
Try
Dim oRE As Regex = New Regex("[^a-zA-Z0-9\s]")
ConvertedTitle = Trim(oRE.Replace(Title, "")).Replace(" ", "_")
Catch ex As Exception
LogError(ex)
End Try
Return ConvertedTitle
End Function
and here's the function I'm calling to return products:
Public Shared Function GetProductByTypeAndTitle(URLFriendlyTitle As String, ProductType As ProductType)
Try
'don't know why, but the server threw errors if I went c.Type=Type
Dim pt As Integer = CInt([Enum].Parse(GetType(ProductType), [Enum].GetName(GetType(ProductType), ProductType)))
Dim context As LionsSharePressEntities = New LionsSharePressModel.LionsSharePressEntities
return From p In context.Products Where GetFriendlyTitle(p.Title) = URLFriendlyTitle AndAlso p.Type = pt
Catch ex As Exception
LogError(ex)
Return nothing
End Try
End Function
It compiles fine, but hangs when I run it. It's that return line that does it.