protected override void BeginProcessing() { if (NoClobber.ToBool()) { if (File.Exists(Path)) { ThrowTerminatingError(new ErrorRecord( new IOException("File already exists. Use -Force to override."), "FileExists", ErrorCategory.ResourceExists, null)); } } System.Text.Encoding useEnc = System.Text.Encoding.ASCII; if (!String.IsNullOrEmpty(Encoding)) { try { useEnc = System.Text.Encoding.GetEncoding(Encoding); } catch (ArgumentException) { // shouldn't happen as Encoding gets validated var msg = String.Format("Invalid encoding '{0}'", Encoding); ThrowTerminatingError(new PSArgumentException(msg).ErrorRecord); } } file = new StreamWriter(Path, false, useEnc); }
protected override void BeginProcessing() { if (NoClobber.ToBool()) { if (File.Exists(Path)) { WriteError(new ErrorRecord( new Exception("File already exists. Use -Force to override."), "FileExists", ErrorCategory.ResourceExists, null)); } } file = new StreamWriter(Path); }