---
updatedAt: 2025-06-05T01:06:47.000Z
agentTools:
  projectIndex: https://api.portal.xpertdoc.com/llms.txt
---

# Testing with C#

For simplicity, all the C# examples will use the methods in this section

## References and Namespace Imports

The methods shown in this page will require that **Xpertdoc.Portal.Sdk** (available on Nuget) to be included as a reference in your project.

Make sure you also include the following:

```csharp
using Xpertdoc.Portal.Sdk;
```

## Setting up the Context

The following code snippet logs the user with either Windows Credentials or Forms Authentication.

```csharp
private const string Username ="username";
private const string Password = "password";
private const string PortalAddress = "http://portal.xpertdoc.com/odata4/v6/";

// If we do not have a username, use our Windows Credentials (DefaultNetworkCredentials)
// Otherwise, use forms authentication (username/password)
var portalContext = string.IsNullOrEmpty(Username) ?
new PortalODataContext(new Uri(PortalAddress))
{
  Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
}
: new PortalODataContext(new Uri(PortalAddress), Username, Password);
```

The context can then be used to query Xpertdoc Portal, the following example will print the name of the first Template Library

```csharp
var templateLibraryName  = portalContext.TemplateLibraries.FirstOrDefault();
Console.WriteLine (templateLibraryName);
```