Thursday, 29 October 2015

How to find files in directory using c#?


Getting a file path :


// This will give the complete path to the folder name  ( ~ File)such as 
//C:\Users\Kumarg\Documents\Visual Studio 2010\Projects\Tag_Cloud\Tag_Cloud\File


string path = Server.MapPath(" ~/folderName");   

Getting all files path under a folder or directory : 


string [ ] fileList = new  string[20];
fileList = Directory.GetFiles(Server.MapPath("~/folderName"));

Getting only file name without the path under a folder or directory 



  var UploadedFile = Directory.GetFiles(Server.MapPath("~/folderName")).Select(f => Path.GetFileName(f));   



No comments:

Post a Comment