Jawad Khan

Jawad's Lodge - The willingness to torture yourself before others is what makes a developer truly a unique breed.
posts - 45, comments - 150, trackbacks - 155

My Links

News

Archives

Post Categories

Image Galleries

Code Conversion Tools ....

I have been asked many times to point to a utility that can convert the sample code or the code snippets found online from Visual basic.Net to C# and Vice versa. After lot of pain and relentless search i have come with following set of useful utilities. They still have their glitches but usually they bring correct result or very near to it. If you know better utlities just post it in the comments section. Thank you in advance ....

  To get the code converted to Visual Basic.NET from C# the following tools are very useful:

    http://www.aspalliance.com/aldotnet/examples/translate.aspx
    http://www.kamalpatel.net/ConvertCSharp2VB.aspx
    http://www.ragingsmurf.com/vbcsharpconverter.aspx

   If someone needs conversion from Visual Basic.NET to C#; they can use following tools:

http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
http://www.codeproject.com/csharp/GBVB.asp

     if you want to spend some money Instant C# and Instant VB seems to be a good choice :

     http://www.tangiblesoftwaresolutions.com/

     Tools that convert both ways ....

     http://www.carlosag.net/Tools/CodeTranslator/Default.aspx (Initially I had problemgetting output from this one. I had to type the VB code manually like Response.Write. When I starting seeing output as I type. I pasted the whole code I wanted to translate) ....

Print | posted on Saturday, May 14, 2005 12:38 PM | Filed Under [ ASP.NET ]

Feedback

Gravatar

# re: Code Conversion Tools ....

using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Jawad.Utils.Printing
{
/// <summary>
/// Summary description for WebPrinting.
/// </summary>
public class WebPrinting
{
public WebPrinting()
{
//
// TODO: Add constructor logic here
//
}

/// <summary>
/// Prints any Control i.e. User Control, DataGrid, Page , Panel etc.
/// </summary>
/// <param name="ctrl">Control to be printed</param>
/// <param name="StyleText">Style to be added in the Head Section</param>
public static void PrintWebControl(Control ctrl)
{
PrintWebControl(ctrl, string.Empty );
}
/// <summary>
/// Prints any Control i.e. User Control, DataGrid, Page , Panel etc.
/// </summary>
/// <param name="ctrl">Control to be printed</param>
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter ();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if ( ctrl is WebControl )
{
Unit w = new Unit(50, UnitType.Pixel);
((WebControl)ctrl).Width = w;
}
Page pg = new Page ();

if (Script != string.Empty )
{
pg.RegisterStartupScript ("PrintJavaScript",Script);
}
HtmlForm frm = new HtmlForm ();
pg.Controls.Add (frm);
frm.Attributes.Add ("runat","server");
frm.Controls.Add (ctrl);
string scr = "<script>function window.onafterprint(){history.back(1);}</script>";
htmlWrite.Write(scr);


pg.DesignerInitialize();
pg.RenderControl(htmlWrite);

string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
}
}

1/7/2008 7:41 AM | ruchi
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: