This isn't exactly a problem with C# coding rules, rather I need help with logic. Here's my situation.
In my program, I deal with a JobID. Say, a print job, and there is a unique (obviously) JobID assigned to each print job. Now, regarding each job there are MANY files associated. Say, JobID = JOB_001 might have to save several files. Then at later times I might need to read those files based on the job id.
So here is the problem. I have a path which is fixed within the scope of the program. Say, ParentPath = "C:\MyFolder".
Now, I need to create a UNIQUE folder for each job under this folder. So, if I have JobIDs JOB_001 and JOB_002, I need two folders as follows.
"C:\MyFolder\JOB_001"
"C:\MyFolder\JOB_002"
The problem? JobID, which is a string, might contain characters that are invalid as folder names. For example, it might have something like JOB_?_001.
So far, I came up with a plan to replace any illegal character with "_" using
System.IO.Path.GetInvalidFileNameChars()
.
So my JobID would change to something like JOB___001.
This works for almost all practical purposes. However, there is a tiny chance, a chance nonetheless, that I might have two JobIDs such as JOB_?_001 and JOB_<_001 or some such character that is invalid as a file path. (I'm working on Windows, and my program runs only on Windows). So, I need the program to be able to tackle this problem as well.
In a nutshell, my primary need is, I need to create unique folders in Windows Platform for each JobID I get, and later be able to access those folders just by specifying the JobID.
Any ideas how I might get around this?