title: Have Sql SMO Delete Database Backup File
body: <p>I have create a C# application that allows a database to be backed up and restored. It does this by first backing the database up to a local file on the Sql server using:</p>
  
  <pre><code>Backup backup = new Backup();
  backup.Devices.AddDevice(Path.GetFullPath(backupFilePath), DeviceType.File);
  ...
  backup.SqlBackup(server);
  </code></pre>
  
  <p>And then I create the new database by restoring from the backup file using:</p>
  
  <pre><code>Restore restore = new Restore();
  restore.Devices.AddDevice(Path.GetFullPath(backupFileToRestoreFrom), DeviceType.File);
  ...
  restore.SqlRestore(server);
  </code></pre>
  
  <p>After the new database has been created I want to delete the temp backup file that we created.  Because I have admin rights on the Sql server box, I can delete the file on the remote server using:</p>
  
  <pre><code>File.Delete("\\SqlServer\C$\Backups\BackupFileToDelete.bak")
  </code></pre>
  
  <p>and it works.  However, if somebody else who doesn't have rights on the Sql server box runs the app, it will throw an exception about not having permissions.</p>
  
  <p>So is there a Sql SMO function that I can call to delete the backup file that was created on the remote Sql server?</p>