Add schema name to views; change FixUpFileName2 to allow drive letters


Thank you to the original author and additional contributors for all of this code.

I downloaded the project code of Version 14428 (May 5, 2013) from:

I discovered a couple of minor issues in this code, and I made the following changes in my local copy.

(1) Change to the FixUpFileName2 method to allow for drive letters
The original version of this method replaced the drive portion of a path such as "C:\Scripts" with "C_\Scripts"
I added a "RegEx replace" wrapper around the updated name string - to replace (at the beginning of the string) a single alpha character followed by "_\" with the same character followed by ":\".
return Regex.Replace(name
.Replace(">", "_")
.Replace("<", "_")
.Replace(":", "_")
.Replace("\"", "_")
.Replace("/", "_")
.Replace("|", "_")
.Replace("?", "_")
.Replace("*", "_")
.Replace("`", "_")
.Replace("'", "_")
.Replace(" ", "_"),
"(^[A-Z,a-z])_\\\\", "$1:\\");
(2) Included the schema name in the file naming for views (since all other objects included the schema name in the file name)

In the method:
private void ScriptViews(Database db)

Changed this line:
using (StreamWriter sw = GetStreamWriter(Path.Combine(views, FixUpFileName(smo.Name) + ".sql"), false))
using (StreamWriter sw = GetStreamWriter(Path.Combine(views, FixUpFileName(string.Format("{0}.{1}.sql", smo.Schema, smo.Name))), false))