Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks alot! Here is a slighlty modified version if your code is written i VB.Net. Just compile and run the converter in every folder that contains aspx sites. </p> <pre><code>using System.IO; namespace Converter { class Program { const string ScriptStartTag = "&lt;script runat=\"server\"&gt;"; const string ScriptEndTag = "&lt;/script&gt;"; static void Main(string[] args) { string currentDirectory = System.Environment.CurrentDirectory; var inPath = new DirectoryInfo(currentDirectory); var outPath = new DirectoryInfo(currentDirectory); 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 = "Imports System\n\n" + "Partial Public Class " + className + " \n Inherits System.Web.UI.Page\n" + "\n" + " " + scriptContents.Trim() + "\nEnd Class\n"; using (TextWriter tw = new StreamWriter(outPath.FullName + "\\" + f.Name + ".vb")) { 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=\"false\" CodeBehind=\"" + f.Name + ".vb\" Inherits=\"" + className + "\" "); using (TextWriter tw = new StreamWriter(outPath.FullName + "\\" + f.Name)) { tw.Write(fileContents); tw.Flush(); } } } } } } </code></pre>
    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. This table or related slice is empty.
    1. 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