I am new to coding and have been doing lots of tutorials recently to learn how to use C# in Visual Studio. I recently started working on a project of my own design. The project is to generate webpages for viewing photos. Part of this requires that I copy a file called main.css to the working directory as this file defines the style of the Webpage. The line of code that I use to write this file is executed by a button click and is as follows:
Assembly.GetExecutingAssembly().GetManifestResourceStream("ThumbsCreator.main.css").CopyTo(new FileStream(folderPath + "//main.css", FileMode.Create));
ThumbsCreator is the namespace name and folderpath is a string containing the path to the working directory. When I run this code the main.css file always turns up but often is blank/empty until I run another function in the program or close the program. This seems to be a little inconsistent on what happens but closing the application always results in the correct content turning up in the css file. The content of the file is just text. Can anybody suggest how I can ensure that the css file is written out immediately after executing the above line of code?