Reputation: 39
I'm working on restAPI project, I have to get list of directories paths, allow the user to choose one and save it in database. I created string variable and wanted to assign selected path to it, but when testing from postman I can't assign full path (e.g C:\dev\data) to string variable (receive bad string format). So I would like to know, what is the best way to store path in db, should I store it without C:\, and if so, how to take directory path without C:\?
Upvotes: 2
Views: 1581
Reputation: 3102
The path "C:\dev\data" will give errors since backslashes are taken as escape sequences. If you need to store the whole path, you should replace the backslash with double backslash for it to work
"C:\\dev\\data\\name_of_file"
You can store this string in the database.
It's best however, to store the main root which in your case is C:\dev\data in a configuration file and just store the file name bit in the DB. To fetch the file from code, you read the folder root from the configuration file and just append the name of your file to it. Hope this helps.
Upvotes: 1
Reputation: 701
As far as I'm aware of, there is no such thing as limitation on what string you can save to certain cell in a DB (in terms of characters). It means, you must have made some mistake along the way.
Make sure first that you can pass chosen path to the back-end. (I assume it is Web-App you work on). Place breakpoint at the action in the controller and check if you receive the string in the first place. Then step-by-step I'd suggest to move down the happy-path and make sure each step works as expected. This way you'll easily locate your error.
Note: It feels like there is high chance of non-escaped characters in the string. Make sure chars are escaped where applicable.
Upvotes: 0