Is there an easy way to take a very long filename (which contains parameters and settings that were used to generate the file) and shorten it programmatically so it will save on Windows?
The filename cannot be sent to a URL shortening service (Bitly, Google, etc.) because the information is confidential and the network is segregated.
The filename has to be shortened internally within the application and without using third-party library and without sending the result to a database.
e.g. Start with a file name so long that Windows will fail to save it:
E:\Results\Job\<SomeJobComponentName>\[A very long file name with the parameters and settings that were used to generate it].csv
And save it as
E:\Results\Job\<SomeJobComponentName>\0eVfd878swg9.csv
And then when the file is read, the code can convert
0eVfd878swg9.csv
back to
[A very long file name with the parameters and settings that were used to generate it].csv
Sort of like a Bitly for filenames.
This is not about encrypting the CONTENT of the file. It's simply about making sure that filenames of any length can be saved without hindrance. The filename needs to be convertible back to the original without opening the file, so that the un-shortened filename can be parsed and viewed in a viewer (which the user uses to browse the result files in the job directory).
I've previously tried the "\?\" prefix to the full path but for whatever reason this fails when using StreamWriter. It can't handle this workaround.
Let me know if I'm barking up the wrong tree here!
Using C# 7.0, Windows Server 2012 R2 and Windows 10 desktop.