I need to load a CSV file into a Neo4j database using its .NET driver. I can use the following code to load the file.
var dataFile = "data.csv";
var driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
using var session = driver.AsyncSession(x => x.WithDefaultAccessMode(AccessMode.Write));
await session.WriteTransactionAsync(async tx =>
{
var result = await tx.RunAsync(
$"LOAD CSV WITH HEADERS FROM 'file:///{dataFile}' AS line " +
"CREATE(:Artist { name: line.Name, year: toInteger(line.Year)})");
});
This requires that the file is located under the C:/Users/user/.Neo4jDesktop/relate-data/dbmss/dbms-502b0f7e-04e2-4c24-9472-528775921429/import/
directory. If the data.csv
file is located under a different directory, and I provide the fully quantifying path, I get the following error.
var dataFile = "C:/Users/user/Desktop/data.csv";
System.AggregateException: 'One or more errors occurred. (Couldn't load the external resource at: file:/C:/Users/user/.Neo4jDesktop/relate-data/dbmss/dbms-502b0f7e-04e2-4c24-9472-528775921429/import/Users/user/Desktop/data.csv)'
I can fix this by commenting-out dbms.directories.import=import
in Neo4j config. However, in my usecase, modifying config is not an option and writing to the .Neo4jDesktop/relate-data/dbmss/dbms-***/import/
is not allowed.
Any thoughts on how I can load CSV from any directory without altering Neo4j configuration?
Changing the config file when importing a file outside "import" folder is a hard rule set by Neo4j. Please chase them about it thru
Why importing file to import folder is not allowed?