# PathHelper

`PathHelper` class provides methods for combine and format `ContentDirectory` paths.

## Configure()

Configure `PathOptions` in composition root of your application and then use [Format()](#format) and [Combine()](#combine) methods.

`PathOptions` properties:

| Property name | Property type                          | Description                                        |
| ------------- | -------------------------------------- | -------------------------------------------------- |
| Template      | `Func<ContentDirectory, string>`       | Determines templates for content directories.      |
| Directories   | `Dictionary<ContentDirectory, string>` | Determines absolute paths for content directories. |

Configure `PathOptions` in `Program.cs` file of ASP.NET application:

```csharp
PathHelper.Configure(options =>
{
    options.Template = (directory) => $"|{directory}Directory|";
    options.Directories[ContentDirectory.Base] = "D:\\WebApp";
    options.Directories[ContentDirectory.Data] = "D:\\WebApp\\App_Data";
});
```

## Combine()

After [configuring](#configure) `PathOptions` you can simply combine `ContentDirectory` absolute path and relative path into a common path.

```csharp
string path = PathHelper.Combine(ContentDirectory.Data, "readme.txt"); // Returns "D:\\WebApp\\App_Data\\readme.txt".
```

## Format()

After [configuring](#configure) `PathOptions` you can simply replace content directory templates from path to content directory absolute paths.

```csharp
var path = "|DataDirectory|\\foo\\bar\\baz.txt";
PathHelper.Configure(options =>
{
    options.Template = (directory) => $"|{directory}Directory|";
    options.Directories[ContentDirectory.Base] = "D:\\WebApp";
    options.Directories[ContentDirectory.Data] = "D:\\WebApp\\App_Data";
});

var result = PathHelper.Format(path, ContentDirectory.Data); // Returns "D:\\WebApp\\App_Data\\foo\\bar\\baz.txt".
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.structr.dev/utilities/io/pathhelper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
