WebMay 2, 2010 · Use DirectoryInfo.GetFiles using System.IO; DirectoryInfo folder = new DirectoryInfo (@"C:\foo\bar"); if (folder.Exists) // else: Invalid folder! { FileInfo [] files = folder.GetFiles ("*.xml"); foreach (FileInfo file in files) { DoSomething (file.FullName); } } Share Improve this answer Follow edited Aug 2, 2016 at 19:39 Sumner Evans WebOct 9, 2014 · It gets the path variable, determines whether it's a dir or a file and then checks to see if it exists. Just make sure you handle the FileAttributes attributes = File.GetAttributes (path); line appropriately such as placing it in a try/catch block because if the file or folder does not exist it will throw an exception. Share Improve this answer
c# - How to check if a specific file exists in directory or any of its ...
WebMay 9, 2016 · You can do the same for other locations. string rootPath = ApplicationData.Current.LocalFolder.Path; string filePath = Path.Combine (rootPath, "fileName.pdf"); if (System.IO.File.Exists (filePath)) { // File exists } else { // File doesn't exist } Share Improve this answer Follow answered Sep 17, 2016 at 18:00 WebApr 28, 2016 · My company's code base contains the following C# line: bool pathExists = Directory.Exists(path); At runtime, the string path happens to be the address of a folder on the company's intranet - something like \\company\companyFolder.When the connection from my Windows machine to the intranet is up, this works fine. new port richey mosque
How to find out a file exists in the direcctory c# - Stack Overflow
WebApr 12, 2024 · C# : How to check if a file exists in a folder?To Access My Live Chat Page, On Google, Search for "hows tech developer connect"As I promised, I have a secret... WebJan 1, 2016 · You need to ensure the directory exists before you can save a file to it. You can do this using the Directory.CreateDirectory method. I would also modify your code to use the Path.Combine method to build your path. WebSep 15, 2024 · The System.IO namespace provides several classes that allow for various actions, such as reading and writing, to be performed on files, directories, and streams. For more information, see File and Stream I/O. Common File Tasks Common Directory Tasks File and Stream I/O Composing Streams Asynchronous File I/O Feedback Submit and … new port richey news in texas