Q:

Downloading PDF from azure fails to load when reopening

I am trying to download a pdf file from azure's blob storage in a memory stream. However, when I try to open the file it does not load.
Here is the code I am using.
Download Code
    protected void blobDownload_Click(object sender, EventArgs e)
    {
        //Getting the blob storage container values
        DBAccess dbaCon = new DBAccess();
        DataTable dt = dbaCon.GetTrainingRecord(TrainingTrainingRecordID.Value);
        string companyID = dt.Rows[0].Field<string>("fk_company_id");
        string blobStorageName = dt.Rows[0].Field<string>("uploaded_file");
        string filename = dt.Rows[0].Field<string>("display_file_name");

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(System.Text.RegularExpressions.Regex.Replace(companyID.ToLower(), @"\s+", ""));
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobStorageName);
        MemoryStream memStream = new MemoryStream();
        blockBlob.DownloadToStream(memStream);
        blockBlob.FetchAttributes();
        HttpResponse response = HttpContext.Current.Response;
        //response.ContentType = blockBlob.Properties.ContentType;
        response.ContentType = "application/pdf";
        response.AddHeader("Content-Disposition", "Attachment; filename=" + filename);
        response.AddHeader("Content-Length", blockBlob.Properties.Length.ToString());
        response.BinaryWrite(memStream.ToArray());
    }

Basically the above code is triggered on a button click, a file is downloaded through the browser but when trying to open the file it cannot be loaded. I have checked  in the azure portal and I am able to directly download the file through the azure portal and the file is fine.
I have tried to directly set the content type and that does not seem to work. 
Pdf files seem to be the only files that don't work I have tested with .jpg and .png files and it downloads and opens fine.
Thanks
Update
The problem has mostly been fixed as it was an issue with the way I was uploading the files. As I needed to store the files uniquely I had to change the name in blob storage to overcome this I used the .SaveAs() function below.
Upload Code
    private void uploadFile(string blobContainer, string randomFileName)
    {
        // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference(blobContainer);

        // Create the container if it doesn't already exist.
        container.CreateIfNotExists();

        // Retrieve reference to a blob named "randomFileName".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(randomFileName);

        filMyFile.PostedFile.SaveAs(Server.MapPath("~/") + randomFileName);

        // Create or overwrite the "myblob" blob with contents from a local file.
        using (filMyFile.PostedFile.InputStream)
        {
            blockBlob.UploadFromStream(filMyFile.PostedFile.InputStream);
        }
    }

The file downloads fine in Edge and chrome however in firefox the name gets shortened and the file extension is missing. The following is a screen shot showing the issue.

A:

Based on my test, your code works corretly on my side. The PDF should be no difference from other blobs. As there is no file type on the azure blob storage, it is just a blob name. The extension type is known for OS.
I recommand that you could  down file named xxx.pdf. Generally we also need PDF reader to read pdf file. If Microsoft Edge browser is installed, you could open the .pdf file directly.

Updated:
For firefox could config it to save the file directly then it should work.

