Avatar of Ruffone
Ruffone
 asked on

How might this method be converted to VB.Net

I ran it through an online converter and wound up with a not so perfect convertion

    private void BuildEmail(string template, Dictionary<string, string> parameters, out string subject, out string body, out string[] attachmentFiles, out string[] linkedResourceFiles)
    {
        ArrayList pathList;

        // Get linked resources
        Regex regex = new Regex("\"cid:([^\"]+)\"", RegexOptions.Multiline | RegexOptions.IgnoreCase);
        Match match = null;

        pathList = ((match = regex.Match(template)) != null) ? new ArrayList() : null;
        while (match.Groups.Count == 2)
        {
            pathList.Add(templateFolder + match.Groups[1].Value);
            match = match.NextMatch();
        }

        linkedResourceFiles = (string[])pathList.ToArray(typeof(string));

        // Get attachments
        regex = new Regex("<!--##ATTACHMENT:([^#]+)##-->");

        pathList = ((match = regex.Match(template)) != null) ? new ArrayList() : null;
        while (match.Groups.Count == 2)
        {
            pathList.Add(templateFolder + match.Groups[1].Value);
            match = match.NextMatch();
        }

        attachmentFiles = (string[])pathList.ToArray(typeof(string));

        // Replace parameters
        template = Regex.Replace(template, "##([^#]+)##",
                                 new MatchEvaluator(delegate(Match m)
                                 {
                                     string value;
                                     if (m.Groups.Count < 2) return m.Groups[0].Value;
                                     return (parameters.TryGetValue(m.Groups[1].Value, out value)) ? value : m.Groups[0].Value;
                                 }));

        // Get body
        body = template;

        // Get subject
        regex = new Regex("<title>(.*)</title>");
        match = regex.Match(template);
        subject = match.Groups[1].Value;
    }

Open in new window

Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
Ruffone

8/22/2022 - Mon
Rose Babu

Try this

Private Sub BuildEmail(template As String, parameters As Dictionary(Of String, String), ByRef subject As String, ByRef body As String, ByRef attachmentFiles As String(), ByRef linkedResourceFiles As String())
	Dim pathList As ArrayList

	' Get linked resources
	Dim regex__1 As New Regex("""cid:([^""]+)""", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
	Dim match As Match = Nothing

	pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
	While match.Groups.Count = 2
		pathList.Add(templateFolder + match.Groups(1).Value)
		match = match.NextMatch()
	End While

	linkedResourceFiles = DirectCast(pathList.ToArray(GetType(String)), String())

	' Get attachments
	regex__1 = New Regex("<!--##ATTACHMENT:([^#]+)##-->")

	pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
	While match.Groups.Count = 2
		pathList.Add(templateFolder + match.Groups(1).Value)
		match = match.NextMatch()
	End While

	attachmentFiles = DirectCast(pathList.ToArray(GetType(String)), String())

	' Replace parameters
	template = Regex.Replace(template, "##([^#]+)##", New MatchEvaluator(Function(m As Match) Do
		Dim value As String
		If m.Groups.Count < 2 Then
			Return m.Groups(0).Value
		End If
		Return If((parameters.TryGetValue(m.Groups(1).Value, value)), value, m.Groups(0).Value)
	End Function))

	' Get body
	body = template

	' Get subject
	regex__1 = New Regex("<title>(.*)</title>")
	match = regex__1.Match(template)
	subject = match.Groups(1).Value
End Sub

Open in new window

asfahani

use the following site to convert from C# to vb.net and vice versa.

http://converter.telerik.com/
systan

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
ExpertLogin_890

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ruffone

ASKER
Thank you