Skip to content

Instantly share code, notes, and snippets.

@SplittyDev
Created December 29, 2013 19:45
Show Gist options
  • Save SplittyDev/8174035 to your computer and use it in GitHub Desktop.
Save SplittyDev/8174035 to your computer and use it in GitHub Desktop.
public byte[] GetRootFile ()
{
try
{
StreamReader reader = new StreamReader (root + "index.html");
string RootFile = reader.ReadToEnd ();
reader.Close ();
string ReplaceString = "&nbsp;&nbsp;&nbsp;&nbsp;Root<br/>";
string[] Directories = Directory.GetDirectories (root, "*", SearchOption.AllDirectories);
int indent = 8;
foreach (string dir in Directories)
{
string realdir = dir;
realdir = realdir.Replace (@"D:/Splitty WebServer/root/", "");
realdir = realdir.Replace (@"\", "/");
for (int i = 0; i < indent; i++) ReplaceString += "&nbsp;";
ReplaceString += "<span class=\"packet\"><span class=\"dir\">Dir</span> " + realdir + "</span><br/>";
string[] Files = Directory.GetFiles (dir);
indent += 4;
foreach (string file in Files)
{
string realfile = file;
realfile = realfile.Replace (@"D:/Splitty WebServer/root/", "");
realfile = realfile.Replace (@"\", "/");
for (int i = 0; i < indent; i++) ReplaceString += "&nbsp;";
ReplaceString += "<span class=\"packet\"><span class=\"file\">File</span> " + realfile + "</span><br/>";
}
indent -= 4;
}
RootFile = RootFile.Replace ("$REPLACE", ReplaceString);
return Encoding.ASCII.GetBytes (RootFile);
}
catch
{
StatusConsole.PrintLine ("Root file not found!", StatusConsole.WarningLevel.warning);
return GetFileContents (root, "404.html");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment