2

I'm trying to implement an AIML bot for my ASP.NET Web Project, but I keep getting this error:

Unable to find the specified file.

Source Error: Line 31:
{

Line 32: myBot = new Bot();

Line 33: myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config");

Line 34: myUser = new User("DefaultUser", this.myBot);

Line 35: AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.myBot);

Here's my code:

protected void Page_Load(object sender, EventArgs e)
{
            myBot = new Bot();
            myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config");
            myUser = new User("DefaultUser", this.myBot);
            AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.myBot);
            this.myBot.isAcceptingUserInput = false;
            loader.loadAIML(@"C:\Users\Public\Documents\SITE\bin\aiml");
            this.myBot.isAcceptingUserInput = true;
}

Sounds to me like it can't find the config folder when running on local host? What am I doing wrong?

MWUser
  • 267
  • 1
  • 7
  • 18
  • Right now it's probably trying to find the file named `config` from the folder `C:\Users\Public\Documents\SITE\bin` (can't tell for sure without seeing the implementation of `loadSettings`). Is `config` a folder? – cbr Mar 02 '15 at 10:58
  • config is a folder @GrawCube It's an API so even I can't access the implementation. Here's the link though: http://en.sourceforge.jp/projects/sfnet_aimlbot/downloads/aimlbot/2.1/AIMLGUI2.1.zip/ – MWUser Mar 02 '15 at 11:09
  • Looking at the source from the SourceForge project, it appears like `loadSettings` tries to find a file called `Settings.xml` in the config folder. Does this file exist? – cbr Mar 02 '15 at 11:16
  • Yes it does! :) But looks like ASP can't locate it through the Path I specified (which is correct since I copied the file's path itself). Do I need to specify something like a Server.MapPath? @GrawCube – MWUser Mar 02 '15 at 11:18
  • I can't unfortunately help you with that - I'm not familiar with ASP at all :) – cbr Mar 02 '15 at 11:22

2 Answers2

1

I know that this an old post but i'm adding my solution just in case someone else is having the same problem.

Your problem is that you don't specify the Settings file.

Try it like this:

 myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config\Settings.xml");

But When deploying the app, the problem will persist because even if you load the settings from your file, the path to other xml files in the config folder will be the same:

 return Path.Combine(Environment.CurrentDirectory, this.GlobalSettings.grabSetting("configdirectory"));

What you can do is: You either add the config directory in C:\Windows\System32\inetsrv or you can download the source code and modify the PathToConfigFiles property to match your requirements, rebuild and add the reference to your project again.

I have modified the property like this:

  private string _pathToConfigFiles;
        public string PathToConfigFiles
        {
            get
            {
                return Path.Combine(this._pathToConfigFiles, this.GlobalSettings.grabSetting("configdirectory"));
            }
            set
            {
                this._pathToConfigFiles = value;
            }
        }

And when i instantiate the bot i have:

   Bot myBot = new Bot();
   myBot.PathToConfigFiles = ConfigurationManager.AppSettings["AimlConfigPath"];
   myBot.loadSettings(ConfigurationManager.AppSettings["AimlSettingsPath"]);

Where "AimlConfigPath" is D:\MyProject\bin and "AimlSettingsPath" is D:\MyProject\bin\config\Settings.xml both added in the web.config file of my app.

Zippy
  • 1,804
  • 5
  • 27
  • 36
0

A good practice for any web project is to include all your files inside the project and access those file-roots.

  1. both @"C:\Users\Public\Documents\SITE\bin\config" and @"C:\Users\Public\Documents\SITE\bin\aiml" should be inside the project. (Just an example if ever your pages are inside a folder).

enter image description here

  1. Using tilde "~" or "../" in ServerMapPath, you should reach your project's ROOT folder and access should look like this (I was able to access the file using File.ReadAllLines("path") for example). enter image description here
  2. Result enter image description here

*NOTE : When rebuilding / debugging, always set the special files as "Always copy" during rebuild, or else the file will not be around when you deploy the web project. enter image description here

ken lacoste
  • 894
  • 8
  • 22