public static string FilenameFromTitle(string name)
{
string safe = name.Trim();
safe = safe.Replace(" ", "-").ToLower();
if(safe.IndexOf("--") > -1)
while(safe.IndexOf("--") > -1)
safe = safe.Replace("--", "-");
safe = Regex.Replace(safe, "[^a-z0-9\\-]", "");
if(safe.Length > 50)
safe = safe.Substring(0, 49);
// clean the beginning and end of the filename
char[] replace = {'-','.'};
safe = safe.TrimStart(replace);
safe = safe.TrimEnd(replace);
return safe;
}