title: How to delete Azure Website Webspace using MAML?
body: <p>I'm trying to figure out how to delete a WebSpace. From what I can tell, I have several empty WebSpaces in my subscription. I'd like to clean them up.</p>
  
  <p>Using the Azure Management Library, I can list out the webspaces in my subscription. I can then list the websites to build a list of webspaces that contain 0 websites. I don't see a way to delete a webspace directly. I can delete a WebHostingPlan though.</p>
  
  <p>The problem I'm having with the code below is when I try to get the WebHostingPlan for a given webspace, I don't get anything. Therefore, without the WebHostingPlan name, I can't delete it.</p>
  
  <p>Does one not delete webspaces, but only WebHostingPlans?  Am I looking at this from the wrong point-of-view?</p>
  
  <pre><code>private async static Task DeleteEmptyWebspaces(SubscriptionCloudCredentials credentials)
  {
      using (var client = new WebSiteManagementClient(credentials))
      {
          var webspaces = await client.WebSpaces.ListAsync();
  
          IDictionary&lt;string, string&gt; spacesToDelete = new Dictionary&lt;string, string&gt;();
          foreach (WebSpacesListResponse.WebSpace space in webspaces)
          {
              var listWebSiteResponse = await client.WebSpaces.ListWebSitesAsync(space.Name, null);
  
              if (listWebSiteResponse.WebSites.Count == 0)
              {
                  var hostingPlanListResponse = await client.WebHostingPlans.ListAsync(space.Name);
                  if (hostingPlanListResponse.Any())
                  {
                      // Assumption: Only one web hosting plan for a web space. Correct?
                      spacesToDelete.Add(space.Name, hostingPlanListResponse.WebHostingPlans[0].Name);
                  }
              }
          }
  
           foreach (var space in spacesToDelete)
           {
              var deleteResponse = await client.WebHostingPlans.DeleteAsync(space.Key, space.Value);
              if (deleteResponse.StatusCode != HttpStatusCode.OK)
              {
                  Console.WriteLine("Failed to delete '{0}'.", space.Key);
              }
           }
      }
  }
  </code></pre>