|
Bin grad dabei mir eine Klasse zu basteln (in VB)
die mir ein aus einem x-beliebigen Web-Formular
eine Mail erstellt da da ja eine wiederverwendbare Komponente
w�re dachte ich mir f�ngst du mal an mit Namespaces
rumzuprobieren. Leider bekomme ich immer eine Fehlermeldung wenn ich meinen
Namespace aufrufen will.
Ich bin so verr�ckt und poste mal den kompletten
Code nehmt es mir nich �bel aber ich hab keine Idee mehr was ich machen
k�nnte
Das ist der Code meiner
Klasse:
Imports System.Collections.Specialized Imports System.Xml Imports System.Web Imports System.Web.Mail Namespace Reissner.WebTools Public Class FormMailer ' Settings ' Private _strMailFrom As String Private _strMailTo As String Private _strMailSubject As String Private _blnIsAlphabeticSort As Boolean Private _strMailText As String Private _blnIsSend As Boolean = False ' Values ' Private _FormValueCollection As NameValueCollection ' Constructor 1 ' Public Sub New(ByVal nvcForm As NameValueCollection) _FormValueCollection = nvcForm End Sub
' Constructor2 ' Public Sub New(ByVal nvcForm As NameValueCollection, ByVal XmlFile As String) _strMailFrom = GetSettingFromXml(XmlFile, "MailFrom") _strMailTo = GetSettingFromXml(XmlFile, "MailTo") _strMailSubject = GetSettingFromXml(XmlFile, "MailSubject") _blnIsAlphabeticSort = GetSettingFromXml(XmlFile, "IsAlphaBetic") _FormValueCollection = nvcForm End Sub ' Public Properties ' Public Property IsAlphabeticSort() As Boolean Get Return _blnIsAlphabeticSort End Get Set(ByVal Value As Boolean) _blnIsAlphabeticSort = Value End Set End Property Public Property MailTo() As String Get Return _strMailTo End Get Set(ByVal Value As String) _strMailTo = Value End Set End Property Public Property MailFrom() As String Get Return _strMailFrom End Get Set(ByVal Value As String) _strMailFrom = Value End Set End Property Public Property MailSubject() As String Get Return _strMailSubject End Get Set(ByVal Value As String) _strMailSubject = Value End Set End Property ' Protected (Private) Methods ' ' Function: Private Function GetSettingFromXml(ByVal XmlFile As String, ByVal Setting As String) As String ' ' Selects the settings from a XmlFile ' Expected structure: ' ' <FormMailer> ' <MailTo></MailTo> ' <MailFrom></MailFrom> ' <MailSubject></MailSubject> ' <SortAlphabetic></SortAlphabetic> '</FormMailer> ' Private Function GetSettingFromXml(ByVal XmlFile As String, ByVal Setting As String) As String Dim configFile As New XmlDocument() Dim asSettings(3) As String Dim ThisSetting As XmlNodeList ThisSetting = configFile.GetElementsByTagName("MailTo") asSettings(0) = ThisSetting.Item(0).InnerText
ThisSetting = configFile.GetElementsByTagName("MailFrom") asSettings(1) = ThisSetting.Item(0).InnerText
ThisSetting = configFile.GetElementsByTagName("MailSubject") asSettings(2) = ThisSetting.Item(0).InnerText
ThisSetting = configFile.GetElementsByTagName("SortAlphabetic") asSettings(3) = ThisSetting.Item(0).InnerText Return asSettings(Setting) End Function ' Public Methods ' ' Function: Public Sub CreateMailFromForm() ' ' Parse the form and create the mailtext Public Sub CreateMailFromForm() Dim intCounter As Integer Dim asValues() As String = _FormValueCollection.AllKeys If _blnIsAlphabeticSort = True Then Array.Sort(asValues) End If Dim dtSetTime As DateTime = Now() _strMailText &= "FormularEintrag vom " & dtSetTime.ToString("F") _strMailText &= "" & vbCrLf & vbCrLf & "--------------------------------------------------------------------------------------------" For intCounter = 0 To asValues.GetUpperBound(0) _strMailText &= "" & vbCrLf & vbCrLf & vbTab & asValues(intCounter) & ": " & _FormValueCollection.Item(asValues(intCounter)) Next intCounter _strMailText &= "" & vbCrLf & vbCrLf & "--------------------------------------------------------------------------------------------" End Sub
' Function: Public Sub SendMail() ' Sends the Mail Public Sub SendMail() SmtpMail.Send(_strMailFrom, _strMailTo, _strMailSubject, _strMailText) End Sub End Class End Namespace Das der der nutzenden
Aspx-Page:
<%@ Page Language="vb" debug="true" %> <%@ Import Namespace = "Reissner.WebTools" %> <% Dim RequestForm As NameValueCollection= Request.Form Dim XmlFile As String = "config.xml" Dim FormMailer As FormMailer = New FormMailer(RequestForm, ServerMapPath(XmlFile)) FormMailer.CreateMailFromForm() FormMailer.SendMail() Response.Write("Versuch!!") %> <%@ Import Namespace = "Reissner.WebTools" %><% Dim RequestForm As NameValueCollection= Request.Form Dim XmlFile As String = "config.xml" Dim FormMailer As FormMailer = New FormMailer(RequestForm, ServerMapPath(XmlFile)) FormMailer.CreateMailFromForm() FormMailer.SendMail() Response.Write("Versuch!!") %><%@ Import Namespace = "Reissner.WebTools" %><% Dim RequestForm As NameValueCollection= Request.Form Dim XmlFile As String = "config.xml" Dim FormMailer As FormMailer = New FormMailer(RequestForm, ServerMapPath(XmlFile)) FormMailer.CreateMailFromForm() FormMailer.SendMail() Response.Write("Versuch!!") %><%@ Import Namespace = "Reissner.WebTools" %><% Dim RequestForm As NameValueCollection= Request.Form Dim XmlFile As String = "config.xml" Dim FormMailer As FormMailer = New FormMailer(RequestForm, ServerMapPath(XmlFile)) FormMailer.CreateMailFromForm() FormMailer.SendMail() Response.Write("Versuch!!") %>Und das ist leider die
Fehlermeldung:
Server Error in '/aspdotnet/Sniplets/TestFormMailerDll' Application.
|
|
Source File: D:\iis5_documents_storage\htdocs\aspdotnet\Sniplets\TestFormMailerDll\sendMail.aspx Line: 12
|
