title: C#: NAudio - Empty path name is not legal
body: <p>I've posted about this before detailing error messages, highlighting where the exception is being thrown, people seem to be ignoring what I write and just dive into the code making guesses.</p>
  
  <p>So I'm going to post the code and while I admit I don't know EXACTLY what is wrong, I know where so I'd appreciate it if you could indulge my newbieness.  </p>
  
  <pre><code>WaveIn sourceStream = null;
      WaveFileWriter waveWriter = null;
      SaveFileDialog save = new SaveFileDialog();
  
   private void sourceStream_DataAvailable(object sender, WaveInEventArgs e)
      {
          if (waveWriter == null) return;
          //Adds bytes to the wave file, storing them in a buffer? 
          waveWriter.Write(e.Buffer, 0, e.BytesRecorded);
          waveWriter.Flush();
      }
  
      private void recordButton_Click(object sender, RoutedEventArgs e)
      {
  
          MainWindow mw = new MainWindow();
          //Get device number from MainWindow.DeviceButton().
          int devNum = mw.DeviceButton();
  
          if (recordButton.Content.ToString() == "RECORD")
          {
              recordButton.Content = "STOP";
              //Start recording audio. 
              sourceStream = new WaveIn();
  
              sourceStream.DeviceNumber = devNum;
  
              //1. Set the sample rate(?). 2. Get number of channels supported on the device.
              sourceStream.WaveFormat = new WaveFormat(44100, WaveIn.GetCapabilities(devNum).Channels);
  
  
              waveWriter = new WaveFileWriter(save.FileName, sourceStream.WaveFormat);
  
              sourceStream.DataAvailable += new EventHandler&lt;WaveInEventArgs&gt;(sourceStream_DataAvailable);
              sourceStream.StartRecording();
          }
          else if(recordButton.Content.ToString() == "STOP")
          {
  
              sourceStream.StopRecording();
              waveWriter.Dispose();
              save.Filter = "Wave Files (*.wav)|*.wav;";
                  if (save.ShowDialog() != true) return;
  
  
  
              recordButton.Content = "RECORD";
  
  
  
          }
      }
  </code></pre>
  
  <p>The error is on this line:</p>
  
  <pre><code>waveWriter = new WaveFileWriter(save.FileName, sourceStream.WaveFormat);
  </code></pre>
  
  <p>It is a runtime error, triggering a System.ArgumentException. Very general, the only useful thing I get is that 'Empty path name is not legal' message.  </p>
  
  <p>Now, I'm following along with some example code in order to familiarize myself with NAudio and they don't ever actually set save.FileName(). So naturally I didn't, honestly I don't think it's necessary or the problem, but thought it worth mentioning just in case.</p>
  
  <p>Personally, and I don't see this in the sample code either, I don't see the connection between the save dialogue and actually saving my audio stream. Perhaps I'm missing this component?</p>