Solved

need help translating code to vb.net from c sharp

Posted on 2006-11-30
2
367 Views
Last Modified: 2010-04-16
Hi Guys,

I have some code that I am pretty sure will do exactly what I want it to do.  I have been working with it today, but I can't get it to work in vb.net.  It is code to get a printer friendly version of a web page to display.  By "Printer friendly version" I mean a web page without the headers and menues.  basically everything *except* the contents of the master page.

Here is the code in c sharp:

 protected void Page_Load(object sender, EventArgs e)
    {

        StringWriter sw = new StringWriter();

        //-- this will get my page, master page and all
        Server.Execute(Request.QueryString["Report"] + ".aspx", sw);

        //-- I shove the HTML in a string
        string report = sw.ToString();
       
        //-- I look for my start and end  of the content
        int iEnd = report.IndexOf("<!-- END REPORT -->");
        report = report.Substring(0, iEnd);

        int iStart = report.IndexOf("<!-- START_REPORT -->");

        //-- this is the page minus master page stuff
        report = report.Substring(iStart, iEnd-iStart);

        //-- shove this in a literal
        this.litReport.Text = report;

    }


********

My markup looks like this:

<body style="margin: 10px;">
    <form id="form1" runat="server">
        <div style="text-align: right;">
            <a href="#" onclick="print();">Print </a>
            <img src="images/spacer.gif" width="50px" height="1px" alt="" />
            <a style="text-decoration:underline; cursor:pointer" onclick="history.back();">Back</a>
        </div>
        <div>
            <asp:Literal ID="litReport" runat="server" />
        </div>
    </form>
</body>

}


If anyone could translate this code successfully into vb.net, it would be greatly appreciated.

Thanks,

Ryan



0
Comment
Question by:dchau12
2 Comments
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 18049826
I don't know anything about web pages but the code should be:

        Dim sw As StringWriter = New StringWriter()

        ' -- this will get my page, master page and all
        Server.Execute(Request.QueryString("Report") & ".aspx", sw)

        ' -- I shove the HTML in a string
        Dim report As String = sw.ToString()
       
        ' -- I look for my start and end  of the content
        Dim iEnd As Integer = report.IndexOf("<!-- END REPORT -->")
        report = report.Substring(0, iEnd)

        Dim iStart As Integer = report.IndexOf("<!-- START_REPORT -->")

        ' -- this is the page minus master page stuff
        report = report.Substring(iStart, iEnd - iStart)

        ' -- shove this in a literal
        Me.litReport.Text = report
0
 
LVL 2

Accepted Solution

by:
amiableansari earned 300 total points
ID: 18051549
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example challenge 10 92
countAbc challenge 9 59
stringclean challenge 26 70
Advice in Xamarin 21 56
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now