If the path is user controlled and potentially contains invalid file system characters then you'll need to ask the user to change the name or normalize out the bad characters in a deterministic way. One method is to replace all invalid characters with say underscore.
public static string NormalizeFileName(string input) {
var invalid = Path.GetInvalidPathChars();
var builder = new System.Text.StringBuilder();
foreach(char c in input) {
if (invalid.Contains(c)) {
builder.Append('_');
} else {
builder.Append(c);
}
}
return builder.ToString();
}
You could then use this function as follows
var originalName = Server.MapPath("..") + name + ".html";
var normalizedName = NormalizeFileName(originalName);
System.IO.File.Create(normalizedName);
EDIT
As several people pointed out, it's best practice to use Path.Combine
here to combine directory and file names.
var originalName = Path.Combine(Server.MapPath(".."), name + ".html");