Retrieve all files from a server side folder

asp.net, c#, file

Solution

You can simplify this using the following code.

public string GetSoundFile()
{
    var files = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/sounds"));
    return String.Join("|",files);
}

Problem

I have the following C# method that retrieves all the files in a folder, and is used in an asp.net application and called by making an AJAX call through JavaScript: ``` public string GetSoundFile(string pSoundFolder) { string[] pFiles = Directory.GetFiles(pSoundFolder); string pFileList = ""; for (int ii = 0; ii < pFiles.Length; ii++) { if (pFileList == "") { pFileList = pFiles[ii]; } else { pFileList += "|" + pFiles[ii]; } } return (pFileList); } ``` and is called by doing the following: ``` oGetSoundFilesJAXHandler.call("C:\\Projects\\"); ``` From what I understand, the line ``` string[] pFiles = Directory.GetFiles(pSoundFolder); ``` is used for local files? The application will be run on the client side and will need to access a server side folder. If I am correct, then my method cannot be adapted to perform the task I need it to. I have tried: ``` oGetSoundFilesJAXHandler.call("~//Projects//"); ``` But this does not return the file list. I have tried searching for a way of achieving my target, but I have not been able to find anything. Maybe I am not using the right keywords in my search, so even keyword hints would be greatly appreciated.

Original source