title: How to validate Azure storage blob names
body: <p>I am implementing an API to store files in Azure Blob Storage.  </p>
  
  <p>I am using the Microsoft library to validate the container and blob name.</p>
  
  <pre><code>NameValidator.ValidateContainerName(containerName);
  NameValidator.ValidateBlobName(blobFullName);
  </code></pre>
  
  <p>However, it is returning some names as valid even though, by <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata" rel="nofollow noreferrer">their own docs</a> I know they are not and when I try to save them, blob storage is returning a 400 bad request, as expected.  So aside from the question as to why the MS validation libraries are incomplete, how can I perform the rest of the validation in C#?  Specifically, I am now failing on the part </p>
  
  <blockquote>
    <p>"some ASCII or Unicode characters, like control characters (0x00 to
    0x1F, \u0081, etc.)"</p>
  </blockquote>
  
  <p>I have a file with \u0081 in the filename.  What are the remaining invalid characters.  They point us to ietf docs, but then say "some" of those characters are not allowed?  Which ones?  Just all control characters?</p>
  
  <p>Just for clarity, here's the part that returns the 400</p>
  
  <pre><code>CloudBlockBlob blob = documentContainer.GetBlockBlobReference(blobFullName);
                  await blob.UploadFromStreamAsync(fileStream, token).ConfigureAwait(false);
  </code></pre>
  
  <p>Thanks for your help!</p>
  
  <p>Update:  I've added this bit of logic to check for control characters at least.  If I can get something somewhat robust, I will issue a PR against Microsoft's validation code</p>
  
  <pre><code>if (blobFullName.ToCharArray().Any(c =&gt; Char.IsControl(c))) {
      throw new HissyFitException();  // or do other stuff to fail validation
  }
  </code></pre>