Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If manual conversion is too time-intensive, and the automatic conversion isn't working, I think your only other option would be to build your own converter. You could write a simple console app which takes a directory path on the command line and processes every file in that directory. This isn't too hard - here, I'll get you started:</p> <pre><code>using System; using System.IO; class Program { const string ScriptStartTag = "&lt;script language=\"CS\" runat=\"server\"&gt;"; const string ScriptEndTag = "&lt;/script&gt;"; static void Main(string[] args) { DirectoryInfo inPath = new DirectoryInfo(args[0]); DirectoryInfo outPath = new DirectoryInfo(args[0] + "\\codebehind"); if (!outPath.Exists) inPath.CreateSubdirectory("codebehind"); foreach (FileInfo f in inPath.GetFiles()) { if (f.FullName.EndsWith(".aspx")) { // READ SOURCE FILE string fileContents; using (TextReader tr = new StreamReader(f.FullName)) { fileContents = tr.ReadToEnd(); } int scriptStart = fileContents.IndexOf(ScriptStartTag); int scriptEnd = fileContents.IndexOf(ScriptEndTag, scriptStart); string className = f.FullName.Remove(f.FullName.Length-5).Replace("\\", "_").Replace(":", "_"); // GENERATE NEW SCRIPT FILE string scriptContents = fileContents.Substring( scriptStart + ScriptStartTag.Length, scriptEnd-(scriptStart + ScriptStartTag.Length)-1); scriptContents = "using System;\n\n" + "public partial class " + className + " : System.Web.UI.Page\n" + "{\n" + " " + scriptContents.Trim() + "\n}"; using (TextWriter tw = new StreamWriter(outPath.FullName + "\\" + f.Name + ".cs")) { tw.Write(scriptContents); tw.Flush(); } // GENERATE NEW MARKUP FILE fileContents = fileContents.Remove( scriptStart, scriptEnd - scriptStart + ScriptEndTag.Length); int pageTagEnd = fileContents.IndexOf("%&gt;"); fileContents = fileContents.Insert(PageTagEnd, "AutoEventWireup=\"true\" CodeBehind=\"" + f.Name + ".cs\" Inherits=\"" + className + "\" "); using (TextWriter tw = new StreamWriter(outPath.FullName + "\\" + f.Name)) { tw.Write(fileContents); tw.Flush(); } } } } } </code></pre> <p>30 minutes coding, 30 minutes debugging. There are some obvious bugs - like, if your code contains a closing script tag anywhere <strong>inside</strong>, then it won't get exported correctly. The results won't be pretty, but this should take care of 90% of your code, and you should be able to clean up any problem results manually. There, does that help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload