Creating a relative path to known folder

I'm looking for a way to make a list of files from a relative filepath.

So far I've come up with this:

string[] filePaths = Directory.GetFiles(@"~\Images\Uploaded\");

But I get an error which says that the path doesn't exist, although it does.

Answers


If it is an ASP.Net application you can use Server.MapPath to convert relative path to absolute path

string folderPath = Server.MapPath("~\Images\Uploaded\");

From the SO answer

You can use Directory.GetcurrentDirectory to get the current directory, and Path.Combine to combine with relative path to form absolute path and get the files from this absolute path.

Try following

string[] filePaths = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),@"\Images\Uploaded\"));

or just use the relative path without using ~

string[] filePaths = Directory.GetFiles(@"\Images\Uploaded\"));

I have not tried it myself, but I'm curious about Directory.GetFiles(VirtualPathUtility.GetDirectory(@"~\Images\Uploaded\"));

VirtualPathUtility documentation


Need Your Help

Python: emulate C-style pass-by-reference for variables

python c reference

I have a framework with some C-like language. Now I'm re-writing that framework and the language is being replaced with Python.

Yii, CactiveForm saving multiples tables in DB

php mysql sql yii

im new at yii and im trying to save datas in different tables on CactiveForm.. this is my code on view: