You can add files
To add a single file: call AddFile
To add a complete directory with subdirs: call AddVirtualDirectory
The first argument is the virtual path on the webserver: so “/” means the file will be accessible from the root. When you call: AddFile( “/test” , “SDpath\image.jpg” ) it will host the image.jpg on url http:///text
public static void Main()
{
using (WebServer server = new WebServer())
{
webServer.AddVirtualDirectory("/", volume.RootDirectory, true);
//server.AddEvent("/", new WebServer.EventCallback(sendForm));
//server.AddEvent("/form", new WebServer.EventCallback(analyseForm));
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
}
public static void Main()
{
if (PersistentStorage.DetectSDCard())
{
using (PersistentStorage storage = new PersistentStorage("SD"))
{
storage.MountFileSystem();
VolumeInfo volume = new VolumeInfo("SD");
}
}
else
{
Debug.Print("SD card not detected");
}
using (WebServer server = new WebServer())
{
server.AddVirtualDirectory("/", volume.RootDirectory, true);
//server.AddEvent("/", new WebServer.EventCallback(sendForm));
//server.AddEvent("/form", new WebServer.EventCallback(analyseForm));
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
}
public static void Main()
{
if (PersistentStorage.DetectSDCard())
{
using (PersistentStorage storage = new PersistentStorage("SD"))
using (WebServer server = new WebServer())
{
storage.MountFileSystem();
VolumeInfo volume = new VolumeInfo("SD");
server.AddVirtualDirectory("/", volume.RootDirectory, true);
Thread.Sleep(Timeout.Infinite);
storage.UnmountFileSystem();
}
}
else
{
Debug.Print("SD card not detected");
}
}
Can one get the files from flash instead of from SD card ?
In my project can i add the web site files to the resource folder and have it grab them from there ?
The only difference will be that, when hosting files from SD-card, the file is read in smaller blocks, so less memory is used. Now you’ll have to load the whole file in RAM and duplicate it, to pass it as a result.
how exactly am i getting my resource file to work in the call ?
// This is my resource file
Resources.StringResources.index
private static void sendForm(object sender, WebServer.EventCallbackEventArgs e)
{
// IS this what would go here ?
e.Response = Resources.StringResources.index;
e.ResponseContentType = "text/html";
}