I can't figure out the correct way to delimit the fields (type, filename, last modified, and size) in my string being returned from an ASP.NET handler page. I am using the following code but my remote directory structure is displaying as shown in the attachment.
Code: Select all
private string GetFileString(string rootPath)
{
StringBuilder sb = new StringBuilder();
DirectoryInfo di = new DirectoryInfo(rootPath);
sb.Append("<pre>");
if (di.Exists)
{
foreach (FileSystemInfo fsi in di.GetFileSystemInfos())
{
sb.Append((fsi.Attributes == FileAttributes.Directory ? "dir " : "file ")).Append(" ");
sb.Append(fsi.LastWriteTime.ToLongTimeString()).Append(" ");
sb.Append((fsi.Attributes == FileAttributes.Directory ? "" : (((FileInfo)fsi).Length / 1024).ToString()) + " KB").Append(" ");
sb.Append(fsi.Name).Append("<br>");
}
}
sb.Append("</pre>");
return sb.ToString();
}
Craig