title: How to show a message box on an invalid filename entered while saving a file using save file dialog
body: <p>Hi all i have written a code to display a message box if invalid characters are entered while saving the file but my message box is not displaying. Actually i will have a save file dialog option to save a file if the filename starts or consists of  the following </p>
  
  <pre><code>             \\/:*?&lt;&gt;|"
  </code></pre>
  
  <p>I would like to display a message box as invalid or illegalcharacters in file</p>
  
  <p>My code is as follows</p>
  
  <pre><code>  Stream myStream;
      SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  
     saveFileDialog1.InitialDirectory = @"C:\";
     saveFileDialog1.DefaultExt = "txt";
     saveFileDialog1.Filter = "(*.txt)|*.txt";
    saveFileDialog1.FilterIndex = 2;
    saveFileDialog1.RestoreDirectory = true;
  
   if (saveFileDialog1.ShowDialog() == DialogResult.OK)
   {
      FileName = saveFileDialog1.FileName;
      if ((FilePathHasInvalidChars(FileName)))
       {
           MessageBox.Show("File name should not contain \\/:*?&lt;&gt;|" ,"", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
       else
       {
           if ((myStream = saveFileDialog1.OpenFile()) != null)
           {
  
                //FileName = saveFileDialog1.FileName;
                if (!(FilePathHasInvalidChars(FileName)))
                {
                   TreeNode newNode = new TreeNode(FileName);
                   newNode.SelectedImageIndex = 1;
                   tvwACH.SelectedNode.Nodes.Add(newNode);
                   TreeNode NodeFileHeader = newNode.Nodes.Add("FileHeader");
                   myStream.Close();
                 }
  
             }
          }
  
       }
  
      public static bool FilePathHasInvalidChars(string path)
      {
  
          return (!string.IsNullOrEmpty(path) &amp;&amp; path.IndexOfAny(System.IO.Path.GetInvalidPathChars()) &gt;= 0);
        }
  </code></pre>
  
  <p>Can any one help me</p>