title: Microsoft Graph API client library - create a folder
body: <p>I'm trying to create a folder under an existing folder in SharePoint using Microsoft Graph (C# SDK). I understand creating the folder on SharePoint or OneDrive should be the same when using the Graph API, but still, I couldn't find any good online references. The only article I found is <a href="https://docs.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&amp;tabs=javascript" rel="nofollow noreferrer">an old one</a>, which only has an example in JavaScript.</p>
  
  <p>I have a root folder <code>A</code> and I want to create a subfolder <code>B</code> under <code>A</code>.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>var driveRequestBuilder = graphClient
      .Sites[SharePointSiteId]
      .Lists[ListId]
      .Drive;
  
  var folderRequestBuilder = driveRequestBuilder
      .Root
      .ItemWithPath("A");
  var folderDriveItem = folderRequestBuilder
      .Request()
      .GetAsync()
      .Result; // This returns the root folder "A"'s info
  
  var subFolderDriveItem = new DriveItem()
  {
      Name = "B",
      Folder = folderDriveItem.Folder
  };
  var result = folderRequestBuilder
      .Request()
      .CreateAsync(subFolderDriveItem)
      .Result;
  </code></pre>
  
  <p>The last line of code throws an <code>AggregateException</code> (because of TPL), which contains the inner exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>Code: -1, Microsoft.SharePoint.Client.InvalidClientQueryException
  Message: The parameter folder does not exist in method getByPath.
  Inner error
  </code></pre>
  
  <p>I want to know the correct syntax to create the subfolder.</p>