I’m building an application that uses an elaborate API to fetch data from Youtube, and the data files are saved with the name of the corresponding video as the file name. However, my program is crashing because quite a lot of the videos on YouTube have characters in their titles that are illegal to use in file names under Windows.
Would URLEncoding the title of the video fix this problem?
If so, is this the best method to use, and what would be the best way to implement a URLEncode?
Thanks! 🙂
Well if you want to do url encoding, you could use
HttpUtility.UrlEncode. I’m not sure I would though. It may strip out all the characters you want it to, but it’ll do others as well.I think I’d probably use
Path.GetInvalidFilenameCharsand just replace anything invalid in the name with an underscore.That’s not a reversible encoding, of course, but I think it’ll produce filenames which are easier to understand. You might want to create an index file which maps from original title to filename as well.