I'm trying to create a DNN module by creating a class library.
but something is wrong when I add a web user control to my project:( I explained all of my actions:)
1- file > new project >
VB class library ( path : desktopModules) ( project name is:TestProj)
2- delete class1.
vb from my project
3- add two references:
DotNetNuke.dll
Microsoft.ApplicationBlocks.Data.dll
4- add new folder : Components , and add 4 classes to it:
DataProvider.
vb
Code:
Imports System
Imports DotNetNuke
Namespace TestProj
Public MustInherit Class DataProvider
#Region "Shared/Static Methods"
' singleton reference to the instantiated object
Private Shared objProvider As DataProvider = Nothing
' constructor
Shared Sub New()
CreateProvider()
End Sub
' dynamically create provider
Private Shared Sub CreateProvider()
objProvider = CType(Framework.Reflection.CreateObject("data", "TestProj", ""), DataProvider)
End Sub
' return the provider
Public Shared Shadows Function Instance() As DataProvider
Return objProvider
End Function
#End Region
#Region "Abstract methods"
Public MustOverride Sub AddContact(ByVal Code As Integer)
Public MustOverride Sub DeleteContact(ByVal Code As Integer)
Public MustOverride Sub UpdateContact(ByVal Code As Integer)
Public MustOverride Function GetContact(ByVal Code As Integer) As IDataReader
Public MustOverride Function GetsContacts(ByVal Code As Integer) As IDataReader
#End Region
End Class
End Namespace
SqlDataProvider.
vb
Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Framework.Providers
Namespace TestProj
Public Class SqlDataProvider
Inherits DataProvider
#Region "Private Members"
Private Const ProviderType As String = "data"
Private Const ModuleQualifier As String = "YourCompany_"
Private _providerConfiguration As ProviderConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType)
Private _connectionString As String
Private _providerPath As String
Private _objectQualifier As String
Private _databaseOwner As String
#End Region
#Region "Constructors"
Public Sub New()
' Read the configuration specific information for this provider
Dim objProvider As Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Provider)
' Read the attributes for this provider
'Get Connection string from web.config
_connectionString = Config.GetConnectionString()
If _connectionString = "" Then
' Use connection string specified in provider
_connectionString = objProvider.Attributes("connectionString")
End If
_providerPath = objProvider.Attributes("providerPath")
_objectQualifier = objProvider.Attributes("objectQualifier")
If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
_objectQualifier += "_"
End If
_databaseOwner = objProvider.Attributes("databaseOwner")
If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
_databaseOwner += "."
End If
End Sub
#End Region
#Region "Properties"
Public ReadOnly Property ConnectionString() As String
Get
Return _connectionString
End Get
End Property
Public ReadOnly Property ProviderPath() As String
Get
Return _providerPath
End Get
End Property
Public ReadOnly Property ObjectQualifier() As String
Get
Return _objectQualifier
End Get
End Property
Public ReadOnly Property DatabaseOwner() As String
Get
Return _databaseOwner
End Get
End Property
#End Region
#Region "Private Methods"
Private Function GetFullyQualifiedName(ByVal name As String) As String
Return DatabaseOwner & ObjectQualifier & ModuleQualifier & name
End Function
Private Function GetNull(ByVal Field As Object) As Object
Return DotNetNuke.Common.Utilities.Null.GetNull(Field, DBNull.Value)
End Function
#End Region
#Region "Public Methods"
Public Overrides Sub DeleteContact(ByVal Code As Integer)
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "judiciary_DeleteContact", Code)
End Sub
Public Overrides Function GetContact(ByVal Code As Integer) As System.Data.IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "judiciary_GetContact", Code), IDataReader)
End Function
Public Overrides Function GetsContacts(ByVal Code As Integer) As System.Data.IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "judiciary_GetsContacts", Code), IDataReader)
End Function
Public Overloads Overrides Sub AddContact(ByVal Code As Integer)
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "judiciary_AddContact", Code)
End Sub
Public Overloads Overrides Sub UpdateContact(ByVal Code As Integer)
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "judiciary_UpdateContact", Code)
End Sub
#End Region
End Class
End Namespace
TestProjInfo.
vb
Code:
Imports System
Imports System.Configuration
Imports System.Data
Namespace TestProj
Public Class TestProjInfo
Private _Code As Integer
Public Property Code() As Integer
Get
Return _Code
End Get
Set(ByVal Value As Integer)
_Code = Value
End Set
End Property
End Class
End Namespace
TestProjController.
vb
Code:
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Xml
Imports System.Web
Imports System.Collections.Generic
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities.XmlUtils
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Search
Namespace TestProj
Public Class TestProjtProjController
#Region "Public Methods"
Public Sub AddContact(ByVal c As TestProjInfo)
DataProvider.Instance.AddContact(c.Code)
End Sub
Public Sub DeleteContact(ByVal Code As Integer)
DataProvider.Instance.DeleteContact(Code)
End Sub
Public Sub UpdateContact(ByVal c As TestProjInfo)
DataProvider.Instance.UpdateContact(c.Code)
End Sub
Public Function GetContact(ByVal Code As Integer) As TestProjInfo
Return CType(DotNetNuke.Common.Utilities.CBO.FillObject(DataProvider.Instance().GetContact(Code), GetType(TestProjInfo)), TestProjInfo)
End Function
Public Function GetsContacts(ByVal Code As Integer) As ArrayList
Return CType(DotNetNuke.Common.Utilities.CBO.FillCollection(DataProvider.Instance().GetsContacts(Code), GetType(TestProjInfo)), ArrayList)
End Function
#End Region
End Class
End Namespace
Until this point I can build my solution successfully . my problem is on add web user control:
5- add new project: asp.net web application and add a web user control to it(ie to my web applicatio proj)
6- drag the WUC.ascx and drop into TestProj ,
first change to WUC.ascx: Inherits="WebApplication2.WUC" ==> Inherits="TestProj.WUC"
second, I changed the WUC.ascx.
vb as follows:
Code:
Imports DotNetNuke
Namespace TestProj
Partial Public Class WUC
Inherits Entities.Modules.PortalModuleBase
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
End Namespace
and then add system.web.dll to my references ( and delete web application from project)
7- build solution succeeded!
BUT: when I double click on my WUC.ascx to see WUC.ascx.
vb I encounter the message alert that: " could not complete the action"
In addition when I want to add this control to my DNN portal it says that:
Error: TEST is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException : Could not load type 'TestProj.WUC'. --->
System.Web.HttpParseException: Could not load type 'TestProj.WUC'. ---> System.Web.HttpParseException: Could not
load type 'TestProj.WUC'. ---> System.Web.HttpException: Could not load type 'TestProj.WUC'. at System.Web.UI.TemplateParser
.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError) at System.Web.UI.TemplateParser.ProcessInheritsAttrib ute
(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) at System.Web.UI.TemplateParser
.PostProcessMainDirectiveAttributes(IDictionary parseData) --- End of inner exception stack trace --- at System
.Web.UI.TemplateParser.ProcessException(Exception ex) at System.Web.UI.TemplateParser.ParseStringInternal(S tring text, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
--- End of inner exception stack trace --- at System
.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding) at System.Web.UI.TemplateParser
.ParseFile(String physicalPath, VirtualPath virtualPath) at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse() at System.Web.Compilation.BaseTemplateBuildProvider.g et_CodeCompilerType()
at System.Web.Compilation.BuildProvider.GetCompilerTy peFromBuildProvider(BuildProvider buildProvider) at
System.Web.Compilation.BuildProvidersCompiler.Proc essBuildProviders() at System.Web.Compilation.BuildProvidersCompiler.
PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile (VirtualPath virtualPath) at System.Web.Compilation.
BuildManager.GetVPathBuildResultInternal(VirtualPa th virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean
allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.UI.TemplateControl.LoadControl(VirtualP ath virtualPath)
at DotNetNuke.UI.ControlUtilities.LoadControl[T](TemplateControl containerControl, String ControlSrc) at DotNetNuke.UI.Modules.ModuleHost
.LoadModuleControl() --- End of inner exception stack trace ---
what is wrong ?