title: Read and write to the same csv file
body: <p>I have a CSV file (E.g. Directories.csv) which contains a huge list of directories. I am looping through the directories from the CSV using streamreader and performing some task. I am updating the completed directory list to a dictionary and stuck at this step now.</p>
  
  <p><strong>Ask:</strong> I want to capture the data through the loop on which directories are complete in the <strong>same CSV</strong> just in case the application crashes or server reboots, so that I don't have to re-iterate through the loop again which got completed. (Or) Delete the completed directories row from the CSV</p>
  
  <p>I tried to check online for suggestions and asking to create temp file and move the copy of it. Can this be possible in case the server reboots or application crashes? Please suggest how can I take this forward. </p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>  Dictionary&lt;string, string&gt; directoryDictionary = new Dictionary&lt;string, string&gt;();
    using (FileStream fileStreamDirectory = File.Open(outputdir + "\\Directories.csv", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    using (BufferedStream bufferStreamDirectory = new BufferedStream(fileStreamDirectory))
    using (StreamReader streamReaderDirectory = new StreamReader(bufferStreamDirectory))
    {
        while ((Directoryline = streamReaderDirectory.ReadLine()) != null)
        {
          #Doing the task here
          directoryDictionary.Add(Directoryline, "Completed");
        }
    }
  </code></pre>