I am getting a System.IO.FileNotFoundException when trying to open a StreamReader on a file that exists in the same directory as Program.cs. try {     using (StreamReader sr = new StreamReader(&quot;file.txt&quot;)) { ... } }  The word file in question exists within the same directory as the program source code. I am using Visual Studio 2019 and this is a simple command line project. So why can't C# find this file, despite it being in the same directory? It doesn't help that Visual Studio won't show me the whole stack trace, but only the one line error.
121720
How do I find out what directory my console app is running in with C#?
63
I am trying to locate a file that (should) contains the string "1896.345", somewhere under /home/dir/.  Any ideas of how I can do it? Thanks
14721
I'm using MonoDevelop to write C# (.NET) codes, on Ubuntu Desktop 14.0.5 LTS. While testing a simple Hello World code, I encountered a problem - earlier on windows, I used the Console.ReadKey() statement to make sure that the console doesn't disappear instantaneously after showing the output. However, this trick is not working on Ubuntu. Here's the code, in case you'd need to see it:  using System;  namespace Project_1 {     class MainClass {         public static void Main (string[] args) {             Console.WriteLine ("Hello World!");             Console.ReadKey ();         }     } }   In spite of the last statement, the console shows up for about 1/100th of a second before disappearing. Precisely, the Console.ReadKey() statement is being ignored(??). I have no idea why this is happening. I'm new to using Ubuntu and installed MonoDevelop a few hours ago.  How do I fix this issue?
15847
When I debug a C# program and I get an exception throwed (either thrown by code OR thrown by the framework), the IDE stops and get me to the corresponding line in my code.  Everything is fine for now.  I then press "F5" to continue. From this moment, it seams like I'm in an infinite loop. The IDE always get me back to the exception line. I have to Shift + F5 (stop debugging/terminate the program) to get out of his.  I talked with some co-workers here and they told me that this happens sometime to them too.  What's happening?
31233
I'm trying to find out how to read/write to the extended file properties in C# e.g. Comment, Bit Rate, Date Accessed, Category etc that you can see in Windows explorer.  Any ideas how to do this? EDIT: I'll mainly be reading/writing to video files (AVI/DIVX/...)
91988
Is it possible to read a .PST file using C#? I would like to do this as a standalone application, not as an Outlook addin (if that is possible).   If have seen     to this mention  but I am looking to do this programmatically in C#.  I have looked at the  namespace but that appears to be just for Outlook addins.  appears to be able to read PST files, but this is in C (sorry Joel, I didn't ).  Any help would be greatly appreciated, thanks!  EDIT:   Thank you all for the responses! I accepted Matthew Ruston's response as the answer because it ultimately led me to the code I was looking for. Here is a simple example of what I got to work (You will need to add a reference to Microsoft.Office.Interop.Outlook):  using System; using System.Collections.Generic; using Microsoft.Office.Interop.Outlook;  namespace PSTReader {     class Program {         static void Main () {             try {                 IEnumerable&lt;MailItem&gt; mailItems = readPst(@"C:\temp\PST\Test.pst", "Test PST");                 foreach (MailItem mailItem in mailItems) {                     Console.WriteLine(mailItem.SenderName + " - " + mailItem.Subject);                 }             } catch (System.Exception ex) {                 Console.WriteLine(ex.Message);             }             Console.ReadLine();         }          private static IEnumerable&lt;MailItem&gt; readPst(string pstFilePath, string pstName) {             List&lt;MailItem&gt; mailItems = new List&lt;MailItem&gt;();             Application app = new Application();             NameSpace outlookNs = app.GetNamespace("MAPI");             // Add PST file (Outlook Data File) to Default Profile             outlookNs.AddStore(pstFilePath);             MAPIFolder rootFolder = outlookNs.Stores[pstName].GetRootFolder();             // Traverse through all folders in the PST file             // TODO: This is not recursive, refactor             Folders subFolders = rootFolder.Folders;             foreach (Folder folder in subFolders) {                 Items items = folder.Items;                 foreach (object item in items) {                     if (item is MailItem) {                         MailItem mailItem = item as MailItem;                         mailItems.Add(mailItem);                     }                 }             }             // Remove PST file from Default Profile             outlookNs.RemoveStore(rootFolder);             return mailItems;         }     } }   Note: This code assumes that Outlook is installed and already configured for the current user. It uses the Default Profile (you can edit the default profile by going to Mail in the Control Panel). One major improvement on this code would be to create a temporary profile to use instead of the Default, then destroy it once completed.
90471
I want to open a certain file extension with a Windows 10 UWP (Microsoft Store) app. I right-click on the file in File Explorer, select Open With, then Chose another app and I get the menu below, which does not include the app I want. At this point, I can click Look for another app on this PC, but the app I need is an UWP one, which is not in the Program Files or Program Files (x86) folders, so I cannot just navigate to the path of the executable file. How can I associate my extension to the UWP app? (Nota that this is not a duplicate of the same question for non-UWP programs)
67491
System.IO.Directory.GetFiles() returns a string[].  What is the default sort order for the returned values?  I'm assuming by name, but if so how much does the current culture effect it?  Can you change it to something like creation date?   Update: MSDN points out that the sort order is not guaranteed for .Net 3.5, but the 2.0 version of the page doesn't say anything at all and neither page will help you sort by things like creation or modification time.  That information is lost once you have the array (it contains only strings).  I could build a comparer that would check for each file it gets, but that means accessing the file system repeatedly when presumably the .GetFiles() method already does this.  Seems very inefficient.
78074
Alright, so I'm working on programming my own installer in C#, and what I'd like to do is something along the lines of put the files in the .exe, so I can do  File.Copy(file, filedir);  Or, if this isn't possible, is there another way of doing what I am attempting to do?
82685
I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.  Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?    Are there special directories?
77250
My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.  I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:     Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point   Huh?  Yes it does... and it was all working 15 min earlier.  Sure, I can believe that I accidentally hit something or done something before I closed it up... but what?  How do I troubleshoot this?    My Program.cs file looks like this:  using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading;  namespace SimpleAIMLEditor {     static class Program     {         [STAThread]         static void Main()         {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);              Application.Run(new mainSAEForm());         }     } }   ...and there are some comments in there.    There are no other errors.  Help?
19207
So my 2009 new years resolution is to learn Java.  I recently acquired "Java for Dummies" and have been following along with the demo code in the book by re-writing it using Eclipse.  Anyway, every example in the book that uses a relative path does not seem to read the .txt file it's supposed to read from.  Here is the sample code:  import java.util.Scanner; import java.io.File; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.GridLayout;  class TeamFrame extends JFrame {      public TeamFrame() throws IOException {         PlayerPlus player;         Scanner myScanner = new Scanner(new File("Hankees.txt"));          for (int num = 1; num &lt;= 9; num++) {             player = new PlayerPlus(myScanner.nextLine(), myScanner.nextDouble());             myScanner.nextLine();             addPlayerInfo(player);         }                add(new JLabel());         add(new JLabel("   ------"));         add(new JLabel("Team Batting Aberage:"));         add(new JLabel(PlayerPlus.findTeamAverageString()));         setTitle("The Hankees");         setLayout(new GridLayout(11,2));         setDefaultCloseOperation(EXIT_ON_CLOSE);         pack();         setVisible(true);     }      void addPlayerInfo(PlayerPlus player) {         add(new JLabel(player.getName()));         add(new JLabel(player.getAverageString()));     } }   And you can see in the below screen shot I have included this file.  image no longer available  Also, I have verified that when I build the application that a copy of Hankees.txt is placed in the bin folder with the compiled .class files.  Lastly, if I change line 12 to the following and place Hankees.txt in the root of my C:\ drive the program compiles and runs fine.  Scanner myScanner = new Scanner(new File("C:\\Hankees.txt"));   So basically, my question is what am I doing wrong?  Or is Eclipse responsible for this in some way?  Thanks for any and all help!
103510
The code below is showing an error as if the file does not exist. I can find the chromedriver.exe file, but the .exe file seems to be non-executable.   These are my commands:  System.setProperty("webdriver.chrome.driver","driver = webdriver.Chrome(executable_path='/usr/local/share/chromedriver')");  WebDriver driver = new ChromeDriver(); driver.get("https://www.youtube.com/");   What may cause this dis-functionality?
92432
I want to both read from and write to a file. This doesn't work.   static void Main(string[] args) {     StreamReader sr = new StreamReader(@"C:\words.txt");     StreamWriter sw = new StreamWriter(@"C:\words.txt"); }   How can I both read from and write to a file in C#?
60633
Sometimes while developing in Visual Studio IDE, when you use "Find in Files"  dialog to find something, the search fails and you will see the following message in the "Find Results" window.      No files were found to look in. Find stopped progress   Once this message shows up, all the subsequent searches will result in the same message. Nothing fixes the problem including restarting the computer except pressing Ctrl + ScrLk.   What causes Visual Studio to get into this state and is there a setting to permanently prevent it from happening?
45531
For example, I rarely need:  using System.Text;   but it's always there by default. I assume the application will use more memory if your code contains unnecessary . But is there anything else I should be aware of?  Also, does it make any difference whatsoever if the same using directive is used in only one file vs. most/all files?    Edit: Note that this question is not about the unrelated concept called a , designed to help one manage resources by ensuring that when an object goes out of scope, its  method is called. See .
11442
I have an application that writes information to file. This information is used post-execution to determine pass/failure/correctness of the application. I'd like to be able to read the file as it is being written so that I can do these pass/failure/correctness checks in real time.  I assume it is possible to do this, but what are the gotcha's involved when using Java? If the reading catches up to the writing, will it just wait for more writes up until the file is closed, or will the read throw an exception at this point? If the latter, what do I do then?   My intuition is currently pushing me towards BufferedStreams. Is this the way to go?