public class FileProvider : MappedPageProvider
{
private string rootFolder;
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{ base.Initialize(name, config);
rootFolder = config["rootFolder"];
}
protected override List<string> GetRootChildren()
{ return Directory.GetFileSystemEntries(rootFolder).ToList();
}
protected override List<string> GetChildren(string Key)
{ if (Directory.Exists(Key))
{ return Directory.GetFileSystemEntries(Key).ToList();
}
else return new List<string>();
}
protected override EPiServer.Core.PageData GetPage(string Key)
{ PageData pd = new PageData();
string parentK = Path.GetDirectoryName(Key);
if (parentK == rootFolder) parentK = null;
FileSystemInfo fsi;
if (Directory.Exists(Key)) fsi = new DirectoryInfo(Key);
else fsi = new FileInfo(Key);
base.InitializePageData(pd, Key, Path.GetFileNameWithoutExtension(Key), parentK);
SetPageStatus(pd, VersionStatus.Published);
if (File.Exists(Key) && (Path.GetExtension(Key).ToLower().EndsWith("txt"))) { StreamReader sr = File.OpenText(Key);
string s = sr.ReadToEnd();
pd.SetValue("MainBody","<pre>"+ s+"</pre>"); sr.Close();
} else pd.SetValue("MainBody", "Creation time: " + fsi.CreationTime.ToString() + "<br/>Last Access Time: " + fsi.LastAccessTime.ToString()); return pd;
}
protected override string GetPageType(string Key)
{ return "[Public] Standard page";
}