2

I have a simple script that creates subdirectory in FileTable:

INSERT INTO MyFiles (name, is_directory)    
VALUES ('SomeFolder', 1, 0)

It works corrrect and if I run it SqlServer creates subdirectory 'SomeFolder'. But if I try to create nested subfolder I face with an error:

INSERT INTO MyFiles (name, is_directory)    
VALUES ('FirstLevel\SecondLevel', 1)

Error message is: An invalid filename, 'FirstLevel\SecondLevel', caused a FileTable check constraint error. Use a valid Windows filename.

As I know I must add parent_path_locator column for parent folder, for instance:

INSERT INTO MyFiles (name, is_directory, parent_path_locator)   
VALUES ('SecondLevel', 1, pathLocatorForFirstLevel)

But I have not pathLocatorForFirstLevel cause FirstLevel is not created yet. Maybe anyone know how to create subfolder with arbitrary name?

Pupkin
  • 1,211
  • 3
  • 13
  • 30
  • 1
    *nix os's use '/' as a folder name separator. Windows uses '\'. No idea if what you're trying will work, though. – simon at rcl Jul 04 '17 at 15:27
  • @simonatrcl I tried to use both variants. It doesn't work unfortunatelly – Pupkin Jul 04 '17 at 15:28
  • Do you need to use FileTableRootPath() along with GetPathLocator() to generate a proper path? See for an example: https://dba.stackexchange.com/questions/73854/how-to-get-sql-server-filetable-path-locator-for-subfolder-by-its-literal-path – Doug Knudsen Jul 04 '17 at 16:07

1 Answers1

-1

Using some C# code, the folder can be quickly verified and created if it does not exist.

using System.IO;            
DirectoryInfo di = Directory.CreateDirectory(FileServerPath + @"\" + 'FirstLevel\SecondLevel');
Blue
  • 22,608
  • 7
  • 62
  • 92
Galactic
  • 400
  • 4
  • 14