[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Convert to ASP.Net from C#

Posted on 2010-11-19
13
Medium Priority
?
574 Views
Last Modified: 2013-11-11
Please help me convert this to asp.net

Thanks Experts
private void ProcessUrl(string url)
    {
        StringBuilder sb = new StringBuilder();

        byte[] buf = new byte[8192];
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream resStream = response.GetResponseStream();

        int count;
        do
        {
            count = resStream.Read(buf, 0, buf.Length);
            if (count != 0)
            {
                string tempString = Encoding.ASCII.GetString(buf, 0, count);
                sb.Append(tempString);
            }
        }
        while (count > 0);

        string document = sb.ToString();
        //document = Regex.Replace(document, "\\n", "", RegexOptions.IgnoreCase);
        document = Regex.Replace(document, "=\"/custom", "=\"" + Request.FilePath, RegexOptions.IgnoreCase);
        document = Regex.Replace(document, "=\"images/", "=\"/LivewireKiosk.com/googlesearch/images/", RegexOptions.IgnoreCase);
        //document = Regex.Replace(document, "align=right", "align=Left", RegexOptions.IgnoreCase);
        // document = Regex.Replace(document, "<div id=res>", "<br><br><br><br><div id=res>", RegexOptions.IgnoreCase);
        document = Regex.Replace(document, "width=100%", "width=75%", RegexOptions.IgnoreCase);
        document = Regex.Replace(document, "width:100%", "width:75%", RegexOptions.IgnoreCase);


        string tmpString = "<table align=right><tr><td align=left><a href=\"http://www.google.com/coop/cse/?hl=en\" target=_top><img src=\"/images/poweredby_transparent/poweredby_FFFFFF.gif\" alt=Google border=0></a><br><span style=\"font-size:9px;font-weight:bolder;color:#000000\">&nbsp;Custom Search</span></td></tr></table>";

        document = document.Replace(tmpString, "");

        string tmpStringCS = "class=\"t bb\"";
        //document = document.Replace(tmpStringCS, "");
      document = Regex.Replace(document, tmpStringCS, "", RegexOptions.IgnoreCase);


        //string GoogleSearchXmlPath = Server.MapPath(ConfigurationManager.AppSettings["GoogleSearchXml"]);
        string GoogleSearchXmlPath = "C:\\Development\\LivewireWebSites\\LivewireKiosk.com\\includes\\googlesearch.xml";
        if (!File.Exists(GoogleSearchXmlPath))
        {
            throw new Exception("The location to the GoogleSearch.xml file is not defined in the Web.Config file attribute GoogleSearchXml");
        }
        XDocument xDocument = XDocument.Load(GoogleSearchXmlPath);
        var items = from item in xDocument.Descendants("Filter") select new {
                        OrgText = ((string)item.Element("OriginalText")),
                        NewText = ((string)item.Element("ReplaceByText"))
        };

        foreach (var item in items)
        {
            document = Regex.Replace(document, item.OrgText, item.NewText, RegexOptions.IgnoreCase);
        }
        SearchResults.Controls.Add(new LiteralControl(document));
    }

Open in new window

0
Comment
Question by:dsiemon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 18

Expert Comment

by:ChetOS82
ID: 34176025
This is already ASP.net.
0
 
LVL 1

Author Comment

by:dsiemon
ID: 34176216
sorry vb.net, from c# to vb.net
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 34176222
There are online tools that do this very well.

http://www.developerfusion.com/tools/convert/csharp-to-vb/
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:ChetOS82
ID: 34176224

Private Sub ProcessUrl(url As String)
	Dim sb As New StringBuilder()

	Dim buf As Byte() = New Byte(8191) {}
	Dim request__1 As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
	Dim response As HttpWebResponse = DirectCast(request__1.GetResponse(), HttpWebResponse)
	Dim resStream As Stream = response.GetResponseStream()

	Dim count As Integer
	Do
		count = resStream.Read(buf, 0, buf.Length)
		If count <> 0 Then
			Dim tempString As String = Encoding.ASCII.GetString(buf, 0, count)
			sb.Append(tempString)
		End If
	Loop While count > 0

	Dim document As String = sb.ToString()
	'document = Regex.Replace(document, "\\n", "", RegexOptions.IgnoreCase);
	document = Regex.Replace(document, "=""/custom", "=""" + Request.FilePath, RegexOptions.IgnoreCase)
	document = Regex.Replace(document, "=""images/", "=""/LivewireKiosk.com/googlesearch/images/", RegexOptions.IgnoreCase)
	'document = Regex.Replace(document, "align=right", "align=Left", RegexOptions.IgnoreCase);
	' document = Regex.Replace(document, "<div id=res>", "<br><br><br><br><div id=res>", RegexOptions.IgnoreCase);
	document = Regex.Replace(document, "width=100%", "width=75%", RegexOptions.IgnoreCase)
	document = Regex.Replace(document, "width:100%", "width:75%", RegexOptions.IgnoreCase)


	Dim tmpString As String = "<table align=right><tr><td align=left><a href=""http://www.google.com/coop/cse/?hl=en"" target=_top><img src=""/images/poweredby_transparent/poweredby_FFFFFF.gif"" alt=Google border=0></a><br><span style=""font-size:9px;font-weight:bolder;color:#000000"">&nbsp;Custom Search</span></td></tr></table>"

	document = document.Replace(tmpString, "")

	Dim tmpStringCS As String = "class=""t bb"""
	'document = document.Replace(tmpStringCS, "");
	document = Regex.Replace(document, tmpStringCS, "", RegexOptions.IgnoreCase)


	'string GoogleSearchXmlPath = Server.MapPath(ConfigurationManager.AppSettings["GoogleSearchXml"]);
	Dim GoogleSearchXmlPath As String = "C:\Development\LivewireWebSites\LivewireKiosk.com\includes\googlesearch.xml"
	If Not File.Exists(GoogleSearchXmlPath) Then
		Throw New Exception("The location to the GoogleSearch.xml file is not defined in the Web.Config file attribute GoogleSearchXml")
	End If
	Dim xDocument__2 As XDocument = XDocument.Load(GoogleSearchXmlPath)
	Dim items = From item In xDocument__2.Descendants("Filter")New With { _
		Key .OrgText = DirectCast(item.Element("OriginalText"), String), _
		Key .NewText = DirectCast(item.Element("ReplaceByText"), String) _
	}

	For Each item As var In items
		document = Regex.Replace(document, item.OrgText, item.NewText, RegexOptions.IgnoreCase)
	Next
	SearchResults.Controls.Add(New LiteralControl(document))
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:dsiemon
ID: 34176423
Dim items = From item In xDocument__2.Descendants("Filter")New With { _
            Key .OrgText = DirectCast(item.Element("OriginalText"), String), _
            Key .NewText = DirectCast(item.Element("ReplaceByText"), String) _
      }

this gives an error:  "Expected end of statement, otherwise everything else is converted

0
 
LVL 1

Author Comment

by:dsiemon
ID: 34176446
i replaced with
Dim items = From item In xDocument__2.Descendants("Filter") Select New With {Key .OrgText = item.Element("OriginalText").ToString, Key .NewText = item.Element("ReplaceByText").ToString}

and now i get 'Item'  wil lbe used as an object, since not no use of 'as'
what should i define it as?

also

below it says Items is not defined

For Each item In items
            document = Regex.Replace(document, item.OrgText, item.NewText, RegexOptions.IgnoreCase)
        Next

Thanks again
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 1000 total points
ID: 34176466
The tools are not converting this properly:

var items = from item in xDocument.Descendants("Filter") select new {
                        OrgText = ((string)item.Element("OriginalText")),
                        NewText = ((string)item.Element("ReplaceByText"))
        };

should be:

Dim items = From item In xDocument__2.Descendants("Filter") _
               Select New With {Key .OrgText = DirectCast(item.Element("OriginalText"), String), Key .NewText = DirectCast(item.Element("ReplaceByText"), String)}
0
 
LVL 1

Author Comment

by:dsiemon
ID: 34176534
ok, after that, what do i declare 'item' as
it keeps saying 'item' is not decalred

For Each item In items
            document = Regex.Replace(document, item.OrgText, item.NewText, RegexOptions.IgnoreCase)
        Next

0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 500 total points
ID: 34177384
i cant believe you posted this on expert exchange

just google "c# to vb" there are plenty of converters

http://www.developerfusion.com/tools/convert/csharp-to-vb/

http://www.dotnetspider.com/convert/Csharp-To-Vb.aspx

and so on
0
 
LVL 18

Assisted Solution

by:ChetOS82
ChetOS82 earned 500 total points
ID: 34189996
Wow Andre, not nice.  Not only has you solution already been presented, but he pointed out that it didn't convert his Linq code properly.
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 1000 total points
ID: 34190442
The following should work in VB.
When you mouse over 'item' it should say "Dim item As <anonymous type>"
Dim items = From item In xDocument__2.Descendants("Filter")
		 Select New With { _
		 .OrgText = item.Element("OriginalText"), _
		 .NewText = item.Element("ReplaceByText")}

		For Each item In items
			document = Regex.Replace(document, item.OrgText.ToString, item.NewText.ToString, RegexOptions.IgnoreCase)
		Next

Open in new window

0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34387743
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question