Simple File Server

Sep 11, 2008 at 5:38 PM
Edited Sep 11, 2008 at 5:41 PM
I'm attempting to create a simple HTTP file server but am having issues. Every time I hit the server with a browser ( either with a valid or invalid url ) it exits with a "System.InvalidOperation: Cannot retrieve files from instance HttpForm.EmptyForm". In the case of a valid url, the server does return the file content to the browser but it still crashes after doing so. I assume I've configured something incorrectly but the chm file does not work on my machine ( no #'s in the path either ).

Edit fun : Apparently Chrome is incompatible with codeplex...

using System;
namespace TestServer
{
  class Program
  {
    class Test
    {
      public void Start()
      {
        HttpServer.HttpServer server = new HttpServer.HttpServer();
        HttpServer.HttpModules.FileModule fileMod = new HttpServer.HttpModules.FileModule("/abc", "c:/users/john/documents");
        fileMod.AddDefaultMimeTypes();
        server.Start(System.Net.IPAddress.Any, 1234);
      }
    }
    static void Main(string[] args)
    {
      try
      {
        Test test = new Test();
        test.Start();
        while (true)
        {
          System.Threading.Thread.Sleep(10000);
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
    }
  }
}

Sep 12, 2008 at 6:28 AM
What version of the server are you using and are you sure you do not add any other modules then the filemodule?

I tested using the #15606 Source Code with this following code and it worked fine:

namespace FileServer
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                HttpServer.HttpServer server = new HttpServer.HttpServer();
                HttpServer.HttpModules.FileModule fileMod = new HttpServer.HttpModules.FileModule("/files", "C:/Documents and Settings/David Dikman/Desktop/");
                fileMod.AddDefaultMimeTypes();
                server.Add(fileMod);
                server.Start(System.Net.IPAddress.Any, 1234);

                while (true)
                {
                    System.Threading.Thread.Sleep(10000);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}


It sound as if you've added ie a ControllerModule and is trying to post a multipart post request (ie a file upload via a html form). For this to work you must make sure a Multipart Decoder has been added (or most easily not add anything and let the standard one fix things for you).
Sep 12, 2008 at 3:26 PM
Edited Sep 12, 2008 at 4:00 PM
The code I posted is my complete app so there's nothing hidden going on - no ControllerModules were added. I was using the beta 1 .dll download. I'll grab the latest source and see if that has the same issue.

EDIT : The tip code appears to fix any issue I was having. Thanks.