Solved

need help translating code to vb.net from c sharp

Posted on 2006-11-30
2
370 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

762 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