Tuesday, July 21, 2009

Check if a table exist using EntitySpaces in DotNetNuke

Using esUtility ExecuteScalar method the function(VB.Net) below given the table name will return true if the table exist in the database otherwise it will return false.

Public Shared Function TableExist(ByVal tableName As String) As Boolean
Dim strSQL As String = "SELECT Count(*) FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}" & tableName & "]') AND OBJECTPROPERTY(id, N'IsTable') = 1"
strSQL = strSQL.Replace("{databaseOwner}", DotNetNuke.Common.Utilities.Config.GetDataBaseOwner())
strSQL = strSQL.Replace("{objectQualifier}", DotNetNuke.Common.Utilities.Config.GetObjectQualifer())

Dim util As New esUtility()
If util.ExecuteScalar(esQueryType.Text, strsql) > 0 Then
Return True
Return False
End If
End Function

Thursday, July 16, 2009

Make sure your Javascripts are in the proper location in DotNetNuke

Calling the procedure below in your DotNetNuke module will make sure that your client script will be inserted in the proper place. Which is inside the Head tag.

The Code:
01.Public Sub InjectClientScript(ByVal page As System.Web.UI.Page, ByVal scriptKey As String, ByVal scriptSrc As String, Optional ByVal scriptValue As String = "")
02.    Dim objHead As Control = page.FindControl("Head")
03.    If objHead IsNot Nothing Then
04.        If objHead.FindControl(scriptKey) Is Nothing Then
05.            Dim jQueryControl As New HtmlGenericControl("script")
06.            jQueryControl.ID = scriptKey
07.            jQueryControl.Attributes.Add("type", "text/javascript")
08.            If scriptValue = "" Then
09.                jQueryControl.Attributes.Add("src", scriptSrc)
10.            Else
11.                jQueryControl.InnerHtml = scriptValue
12.            End If
13.            objHead.Controls.Add(jQueryControl)
14.        End If
15.    End If
16.End Sub

Inserting a script file;
1.InjectClientScript(page, "jquery.1.3.2.min.js", "/js/jquery.1.3.2.min.js")

1.<script id="jquery.1.3.2.min.js" type="text/javascript" src="/js/jquery.1.3.2.min.js"></script>

Inserting a plain script;
1.InjectClientScript(page, "jQueryNoConflict", "", "jQuery.noConflict();")

1.<script id="jQueryNoConflict" type="text/javascript">jQuery.noConflict();</script>