Convert HTML to .aspx?

Last post 06-21-2009 2:37 AM by TATWORTH. 18 replies.

Sort Posts:

  • Convert HTML to .aspx?

    05-28-2008, 9:30 PM
    • Member
      148 point Member
    • aliasncnu
    • Member since 03-18-2007, 2:08 PM
    • Taiwan
    • Posts 333

    Hello,

    is there this kind of tool available in the market?

    I have found several ones, but they all out of date.

    Regards,

    Ricky.

    Take nothing on looks; take everything on evidence.
    - Charles Dickens
  • Re: Convert HTML to .aspx?

    05-28-2008, 11:31 PM
    • All-Star
      17,458 point All-Star
    • albertpascual
    • Member since 05-23-2003, 2:11 PM
    • Riverside, CA
    • Posts 3,474

    You should be able to just copy the whole thing into the aspx and add runat="server" to the controls you want to use on the code behind.

    Cheers
    Al
    My Blog
    MapStats.NET
    Please click on 'Mark as Answer' if this post answered your question!
  • Re: Convert HTML to .aspx?

    06-02-2008, 10:38 AM
    • Member
      148 point Member
    • aliasncnu
    • Member since 03-18-2007, 2:08 PM
    • Taiwan
    • Posts 333

    Hello, what I am thinking is that if we can edit HTML online, and then convert HTML to ASPX tags, not a copy-and-paste solution.

    Anyidea?

    Regards,

    Ricky.

    Take nothing on looks; take everything on evidence.
    - Charles Dickens
  • Re: Convert HTML to .aspx?

    08-09-2008, 3:16 AM
    • Member
      9 point Member
    • pentahari
    • Member since 03-19-2008, 8:05 AM
    • Posts 29

    aliasncnu:

    Hello,

    is there this kind of tool available in the market?

    I have found several ones, but they all out of date.

    Regards,

    Ricky.

     

    why you want?

  • Re: Convert HTML to .aspx?

    08-15-2008, 6:42 AM
    • Contributor
      2,167 point Contributor
    • AliSufyanButt
    • Member since 06-05-2007, 10:01 AM
    • Islamabad-Pakistan
    • Posts 625

    Html controls are light weight controls.

    Asp.net are slightly Heavy controls with extended features that has potential to execute server side code.

    The syntax is all around different. there is a seperate set of controls in Asp.net. So would have to do a redesign of the form. That would be the best option. And would not take too long either.

    Do mark as answer if it helps

    Best Regards

    Ali Sufyan Butt
    Software Engineer
    Electronic Solutions Pvt. Limited
  • Re: Convert HTML to .aspx?

    08-29-2008, 1:54 AM
    • Contributor
      4,447 point Contributor
    • worldspawn[]
    • Member since 01-19-2003, 6:21 PM
    • Melbourne, Australia
    • Posts 943

    C:\html>ren *.html *.aspx

    Done!!

     

    -- Sam Critchley

    "Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT

    website design
    internet marketing
  • Re: Convert HTML to .aspx?

    08-29-2008, 3:20 AM
    • Contributor
      2,167 point Contributor
    • AliSufyanButt
    • Member since 06-05-2007, 10:01 AM
    • Islamabad-Pakistan
    • Posts 625

    The solution you are providing is not converting html to aspx but is just renaming html to aspx

    By your procedure, one would not be able to use asp.net server controls and any vb.net or C# code behind. The purpose of html to aspx is obviously to use asp.net controls. Your solution would not work in this scenerio.

    Do mark as answer if it helps

    Best Regards

    Ali Sufyan Butt
    Software Engineer
    Electronic Solutions Pvt. Limited
  • Re: Convert HTML to .aspx?

    10-03-2008, 2:51 PM

     Hello,

     Never seemed to have found a tool to do this, but I was able to convert HTML to ASPX pages manually and place asp objects on the page. If you would like to know how I did it I would be more then happy to tell you. Smile

    ===============
    I want to be a PROGRAMMER!!!
  • Re: Convert HTML to .aspx?

    12-04-2008, 1:42 AM

    Html cannot be converted into Aspx directly. Better option is to copy the html code and paste in the newly created aspx page. set runat="server" in the form tag.

  • Re: Convert HTML to .aspx?

    12-09-2008, 2:19 AM
    • Member
      2 point Member
    • censor
    • Member since 12-09-2008, 7:13 AM
    • Posts 1

    Hello,

    And yes, I sure would like to know how you did it. I'm in my last year, and for my endwork, we have got mazy html pages of a site that need to be converted into asp. How did you do it?

     

    Thanks for letting me know. 

  • Re: Convert HTML to .aspx?

    12-10-2008, 1:11 PM
    • Member
      102 point Member
    • tekknowledge
    • Member since 09-19-2008, 3:57 PM
    • Posts 69

    sure, its a button called find/replace in visual studio =p once you copy and paste...but seriously i havent ran into anything like that

  • Re: Convert HTML to .aspx?

    12-11-2008, 11:30 PM
    • Contributor
      4,447 point Contributor
    • worldspawn[]
    • Member since 01-19-2003, 6:21 PM
    • Melbourne, Australia
    • Posts 943

    AliSufyanButt you have no sense of humor do u? With a name like yours that's not that surprising.

    Creating a bit of code that will recurse a directory tree creating aspx pages from html files would be very easy. It could create an accompanying .cs file and put the <%@ Page %> element in the aspx file. All laughably easy.

    Seems like you have some sort of expectation to convert html tags into asp tags. I guess it could add a runat="server" attribute to the head tag. Beyond that I don't see any what else it could do; What other tags would it asp-ise??

    -- Sam Critchley

    "Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT

    website design
    internet marketing
  • Re: Convert HTML to .aspx?

    12-12-2008, 12:43 AM
    • Contributor
      4,447 point Contributor
    • worldspawn[]
    • Member since 01-19-2003, 6:21 PM
    • Melbourne, Australia
    • Posts 943

    Ok heres some VERY rough VERY crap VERY inefficient code that does a bit of the work. Creates c# compatible namespaces, classname (1 minute of testing says it does anyway).

    Also note theres some hard coded paths in for the DEBUG code path. Change em. ALSO THE DEBUG CODE DELETE THE CONTENTS OF THE OUTPUT PATH!! U WERE WARNED.

    Post what's missing please. So far I have:

    • Doesn't handle form tag

     

    Here it is, hack freely:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Text.RegularExpressions;

    namespace ASPXOMatic
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    FolderBrowserDialog selectFolderDialog = new FolderBrowserDialog();
    selectFolderDialog.Description = "Select the folder to search for html files.";

    string scanPath;
    string outputPath;

    #if !DEBUG
    var result = selectFolderDialog.ShowDialog();

    if (result != DialogResult.OK)
    return;

    scanPath = selectFolderDialog.SelectedPath;
    #else
    scanPath = "C:\\tmp\\service terminal";
    #endif
    selectFolderDialog.Description = "Select the folder to output conversions.";
    #if !DEBUG
    result = selectFolderDialog.ShowDialog();

    if (result != DialogResult.OK)
    return;
    outputPath = selectFolderDialog.SelectedPath;
    #else
    outputPath = "C:\\tmp\\foo";
    new DirectoryInfo(outputPath).Delete(true);
    Directory.CreateDirectory(outputPath);
    #endif

    DirectoryInfo scanFolder = new DirectoryInfo(scanPath);

    List workUnit = new List();
    workUnit.AddRange(scanFolder.GetFiles("*.html", SearchOption.AllDirectories));
    workUnit.AddRange(scanFolder.GetFiles("*.htm", SearchOption.AllDirectories));

    string pageDirective = @"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""{0}.cs"" Inherits=""{1}"" Title=""{2}"" %>";
    string ns = "MyApp.MyTest";//add some kinda prompter here.

    string pageSource =
    @"using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    namespace {0}
    {{
    public partial class {1} : System.Web.UI.Page
    {{
    }}
    }}"
    ;

    foreach (FileInfo htmlFile in workUnit)
    {
    string relativePath = htmlFile.DirectoryName.Replace(scanPath + "\\", string.Empty);
    string newPath = Path.Combine(outputPath, relativePath);
    if (!Directory.Exists(newPath))
    {
    Directory.CreateDirectory(newPath);
    }

    string fileNs = ns;
    if (!string.IsNullOrEmpty(relativePath))
    {
    fileNs += "." + relativePath.Replace('\\', '.');
    Regex ex = new Regex("\\.(\\d)");
    fileNs = ex.Replace(fileNs, "._$1");
    ex = new Regex("\\.([a-z])");
    fileNs = ex.Replace(fileNs, new MatchEvaluator(p => "." + p.Groups[1].Value.ToUpper()));
    }

    string name = Path.GetFileNameWithoutExtension(htmlFile.Name);
    string className = name;
    Regex fex = new Regex("[^A-Za-z\\d]");
    className = fex.Replace(className, string.Empty);
    fex = new Regex("^(\\d)");
    className = fex.Replace(className, "_$1");

    string fileSource = htmlFile.OpenText().ReadToEnd();
    fex = new Regex("<title>(.+)</title>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
    Match m = fex.Match(fileSource);
    string title = m.Success ? m.Groups[1].Value : "Untitled Page";
    string directive = string.Format(pageDirective, name + ".aspx", fileNs + "." + className, title);

    fex = new Regex("<(head)>", RegexOptions.IgnoreCase);
    fileSource = fex.Replace(fileSource, "<$1 runat=\"server\">");

    StringBuilder newSource = new StringBuilder();
    newSource.AppendLine(directive);
    newSource.Append(fileSource);

    StreamWriter newOut = new StreamWriter(Path.Combine(newPath, name + ".aspx"));
    newOut.Write(newSource.ToString());
    newOut.Close();

    string codeBehind = string.Format(pageSource, fileNs, className);
    newOut = new StreamWriter(Path.Combine(newPath, name + ".aspx.cs"));
    newOut.Write(codeBehind);
    newOut.Close();
    }
    }
    }
    }
      
    -- Sam Critchley

    "Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT

    website design
    internet marketing
  • Re: Convert HTML to .aspx?

    12-15-2008, 12:45 PM
    • All-Star
      63,198 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,340
    • TrustedFriends-MVPs

     There is a useful HTML to generated builder function at http://www.codeplex.com/HtmlTextWriterUtil

    From the site:

    Features

    - Converts HTML, CSS, JavaScript and other types of web content to C# code, mainly for use in the Render method of web parts;
    - Set the name of the HtmlTextWriter instance;
    - Choose between HtmlTextWriter only code and StringBuilder code;
    - Copy result to clipboard.
     

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Convert HTML to .aspx?

    05-20-2009, 5:03 AM
    • Member
      10 point Member
    • jadavdinesh7
    • Member since 12-09-2008, 5:45 PM
    • Posts 5

     hi everyone right now iam facing the same problem i,e "Convert HTML page to ASP.NET page". iam unable to do.plz i need a help  from anyone. so i think some will help me.

    Thanks in advance.

    dinnu.

     

Page 1 of 2 (19 items) 1 2 Next >