Optionally provide private feedback to help us improve this article...

Thank you for your feedback!


Using the InstantKB API

New

We've made it very easy for developers to take advantage of the InstantKB .NET API from your existing ASP.NET based web site or web application. Adding references to our assemblies allows you to create, read, update or delete data from any InstantKB database table within your own web site or web application. 

InstantKB targets .NET 4.0 or above. You should ensure your Visual Studio projects also target .NET 4.0 or above before adding any references to our assemblies. 

To take advantage of the InstantKB .NET API from your own Visual Studio projects please follow the steps below.

1. Add References to our .NET Assemblies

Right click on your web site within Visual Studio solution explorer and locate the "Add Reference " option...



This will display the Visual Studio / Add Reference dialog. Select the "Browse" Tab and locate the InstantKB DLL files.

Select the assemblies shown below…

  • InstantASP.Common.Configuration.dll
  • InstantASP.Common.Data.dll
  • InstantASP.Common.dll
  • InstantASP.Common.UI.dll
  • InstantASP.InstantKB.Data.dll
  • InstantASP.InstantKB.dll
  • InstantASP.InstantKB.UI.dll

This will ensure you have access to all the methods within our API.

2. Add the InstantKB database connection string to your web sites web.config file

To ensure our API knows where to look for data you'll need to provide a database connection string within your web.config file within the <appSettings> section…

<appSettings>
<add key="InstantASP_ConnectionString" value="server=localhost;uid=Username;pwd=Password;database=InstantKB20"/>
</appSettings>

You can also use the connection string below if you have both InstantKB & InstantForum.NET references within your project…

<appSettings>
<add key="InstantKB_ConnectionString" value="server=localhost;uid=Username;pwd=Password;database=InstantKB20"/>
</appSettings>

3. Add the InstantKB path to your web sites web.config file (optional)

This indicates the virtual path to the InstantKB installation from the root o your web application referencing our assemblies. For example if InstantKB is installed in a child folder under your main site within a folder called "kb" this application setting would look like...

<add key="InstantASP_VirtualPath" value="kb"/>

If you install the forum to a web application located at c:\test\ but you wanted to add the forum to c:\test\support\kb\ you would modify the setting InstantASP_VirtualPath to read "forums/myforum"…

<add key="InstantASP_VirtualPath" value="support/kb"/>

4. Testing the references are working correctly

To quickly test the references are working correctly lets return some user data using the InstantKB API. You can use the following code to get an instance of the default administrator account provided with InstantKB and display some user properties on your page…

public class _Default : System.Web.UI.Page
{


protected void Page_Load(object sender, System.EventArgs e)
{
InstantASP.InstantKB.Components.User User = new InstantASP.InstantKB.Components.User(1);


if (User.UserID > 0) {
var _with1 = Response;
_with1.Write("User Information");
_with1.Write("");
_with1.Write("-----------------");
_with1.Write("");
_with1.Write(User.Username);
_with1.Write("");
_with1.Write(User.EmailAddress);

}

}
public _Default()
{
Load += Page_Load;
}

}

Why do I need the InstantASP_VirtualPath setting?

InstantKB needs to know where to find localization & continuation files for some operations within our API. For example all page names are held within the "Pages.config" file within InstantKB. This allows you to use our API to get forum URLs. For example if you wanted to populate a hyperlink to a specific forum you could use…

hypMyLink.NavigateURL = "~/kb/" + InstantASP.InstantKB.Globals.Paths.Article(intArticleID)

In this instance InstantKB will attempt to look within the "Pages.config" file within the root of an InstantKB installation to get the name for the knowledgebase page. Providing the InstantASP_VirtualPath path setting allows our API to correctly locate these files and use any customizations you've defined.

If you don't provide a InstantASP_VirtualPath path setting InstantKB will fall back to use the default settings for paths and settings within Pags.config & other files simply won't be used.

If you copy the Pages.config & URLRewrite.config files into the root of your own ASP.NET project referencing our assemblies you can ignore this setting. Our assemblies will always look for Pages.config & URLRewrite.config in the root of your web application unless you provide a InstantASP_VirtualPath setting as shown above.

I get a "The ConnectionString property has not been initialized" error?

This error occurs if you've not provided the required database connection string so our API knows where to look for InstantKB data. For further information please see step 2 above.