Could not find a part of the path 'C:\

c#, directory

Solution

You're formatting the date as part of the filename in such a way that the date separators are slashes, which get converted to backslashes (path separators) by the path logic:

'C:\CMSExportedData\Sales-20\07\2012.txt'.

There's no Sales-20 folder, and no 07 folder.

Solution: don't use path separator characters in your file names :). This solution also formats the date as year-month-day because that makes the file names sort in chronological order:

"C:\\CMSExportedData\\Sales-" + DateTime.Now.ToString("yyyyMMdd") + ".txt"

Problem

Im getting this error. Even though i already created a folder "CMSExportedData" Could not find a part of the path 'C:\CMSExportedData\Sales-20\07\2012.txt'. Kindly help please ``` using (FileStream fs = new FileStream("C:\\CMSExportedData\\Sales-" + DateTime.Now.ToString("dd/MM/yyyy") + ".txt", FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.Default)) { //use stream } } ```

Original source