Skip to content

Redirecting the workspace to another location, as shown in the readme, doesn't work #27

Closed

Description

@wags1999

The readme contains these instructions for redirecting the workspace, using ArtifactStorageOptions.WorkspacePathFormatter to override the path:

var workspaceRoot = Path.Combine(Path.GetTempPath(), "markitdown", "workspaces");

var options = new MarkItDownOptions
{
    ArtifactStorage = ArtifactStorageOptions.Default with
    {
        WorkspacePathFormatter = name => Path.Combine(workspaceRoot, name),
        DeleteOnDispose = false    // keep the workspace directory after conversion
    },
    SegmentOptions = SegmentOptions.Default with
    {
        Image = SegmentOptions.Default.Image with
        {
            KeepArtifactDirectory = true
        }
    }
};

Directory.CreateDirectory(workspaceRoot);

await using var client = new MarkItDownClient(options);
await using var result = await client.ConvertAsync("policy.pdf");

However, before the call to the WorkspacePathFormatter is invoked on line 36:

var directoryPath = storageOptions.WorkspacePathFormatter?.Invoke(workspaceName)

On lines 27-32, if the StorageFactory was not setup on the options, a default path will be returned:
if (storageFactory is null)
{
var localDirectory = BuildLocalWorkspacePath(streamInfo, segmentOptions.Image);
var deleteOnDispose = storageOptions.DeleteOnDispose && !segmentOptions.Image.KeepArtifactDirectory;
return ArtifactWorkspace.Create(localDirectory, deleteOnDispose, ensureCreated: true);
}

Using ManagedCode.MarkItDown 10.0.6

Activity

  1. wags1999 commented on Mar 2, 2026

    @wags1999
    Author

    After source code spelunking, the right way to override the temp directory that MarkItDown uses is:

    var options = new MarkItDownOptions
    {
        RootPath = workspaceRoot
    };
    

    or in your Program.cs:

    builder.Services.AddMarkItDown().UseRootPath(workspaceRoot);
    

    Would be great if the Readme pointed at these options.

  2. edgett commented on Mar 4, 2026

    @edgett

    I made #28 to resolve this.

  3. KSemenenko commented on Apr 5, 2026

    @KSemenenko
    Member

    Just merged! Thanks a lot!

  4. KSemenenko commented on Apr 5, 2026

    @KSemenenko
    Member

    Please check latest version and let me know

  5. wags1999 commented on Apr 6, 2026

    @wags1999
    Author

    Looks great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions