Categories
Coding

Mapping SQL Server integer types to .NET types

BigInt = Int64 (Long)
Int = Int32 (Integer)
SmallInt = Int16 (Short)
TinyInt = Byte

e.g. byte recurrenceType = reader.GetByte(8);

Categories
Coding

Detecting Mobile Devices with ASP.NET

I’ve no imediate use for this code, but I know wthat it will be useful in the future – especially as the number of user’s accessing websites via mobile phones and PDAs grow.

Taken from a post by truelove.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim Browser_obj As System.Web.Mobile.MobileCapabilities = CType(Request.Browser, System.Web.Mobile.MobileCapabilities)
If Browser_obj.Browser = "Pocket IE" Then
Label1.Text = "the is Pocket PC"
ElseIf Browser_obj.Browser = "IE" Then
Label1.Text = "Microsoft Internet Explorer"
ElseIf Browser_obj.Browser = "Phone.com" Then
Label1.Text = "the is Openwave"
End If
End If
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim browser As System.Web.Mobile.MobileCapabilities = CType(Request.Browser, System.Web.Mobile.MobileCapabilities)
If browser.ScreenCharactersWidth < 20 Then Label1.Text = "short text message" Else Label1.Text = "long text message" End If End If End Sub

Categories
Coding

Copying data to the clipboard using C#

Clipboard.SetText( “Hello World!”);

Short and sweet! 🙂

Categories
Coding

Row numbers within MySQL

Sometime you will need a query that will return a resultset of ranked records. The following MySQL query will do the trick:

SELECT @rownum:=@rownum+1 AS rank, companies.* FROM conpanies p, (SELECT @rownum:=0) r ORDER BY profit DESC LIMIT 20;

Categories
Coding

Skype buttons

I had used this service before and spent a while trying to track down the URL again. Here it is for future reference.

http://www.skype.com/intl/en/share/buttons/wizard.html

Categories
Coding

A minimal XHTML document

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>title</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="script.js"></script>
</head>
<body>

</body>
</html>
Categories
Coding

Strip HTML Tags from a String

Private Function ConvertHtmlToPlainText(ByVal htmlText As String) As String
Return Regex.Replace(htmlText, "<[^>]*>", String.Empty)
End Function

Categories
Coding

Converting C# to VB.Net

Thanks to a reply to one of my posts within the SubSonic forums, I was pointed to this very nifty utility at Developer Fusion – a tool that will automatically convert C# code to VB.Net and back again.

Categories
Coding

Intellisense within SubSonic

I struggled for a while this morning while trying to add SubSonic to a new web project – I was trying to fathom why, when I had followed all of my notes, the intellisence for the build provider was not displaying. In the end, the issue was solved with the help of this post.

Addendum:

Categories
Coding

Converting URLs into Hyperlinks

This is a essential peice of Classic ASP code I’ve used time after time for my websites – originally taken from 4GuysFromRolla.com, I’m pasting it here for future reference.

'----------------------------------------------
' InsertHyperlinks(inText)
' Returns a inText with "<a target="_BLANK" href="URL" mce_href="URL">URL</a>"
' inserted where there is URL found.
'
' URL can start with "www" or "http"
' or
' URL can be a email address "*@*"
'----------------------------------------------
Function InsertHyperlinks(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd
strBuf = ""
  iStart = 1
  iEnd = 1
  Set objRegExp = New RegExp
objRegExp.Pattern = "\b(www|http|\S+@)\S+\b" ' Match URLs and emails
  objRegExp.IgnoreCase = True ' Set case insensitivity.
  objRegExp.Global = True ' Set global applicability.
  Set objMatches = objRegExp.Execute(inText)
  For Each objMatch in objMatches
  iEnd = objMatch.FirstIndex
  strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
  If InStr(1, objMatch.Value, "@") Then
  strBuf = strBuf & GetHref(objMatch.Value, "EMAIL", "_BLANK")
  Else
  strBuf = strBuf & GetHref(objMatch.Value, "WEB", "_BLANK")
  End If
  iStart = iEnd+objMatch.Length+1
  Next
  strBuf = strBuf & Mid(inText, iStart)
  InsertHyperlinks = strBuf
End Function

Function GetHref(url, urlType, Target)
Dim strBuf
strBuf = "<a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target=""" & _
Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
GetHref = strBuf
End Function