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

Good class design by example

c# design c#-4.0

I am trying to work out the best way to design a class that has its properties persisted in a database. Let's take a basic example of a Person. To create a new person and place it in the database, ...

Spatial Data SQL Reprojection Function issues

sql postgresql gis postgis sql-function

Hello I am just learning postGIS and thus postgresql (9.1) and am trying to save some time copying the same code over and over by creating an sql function to reproject some spatial data.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.