Example #1
0
        public static string DownloadPageBlob(CloudPageBlob blob, string LocalDownloadPath)
        {
            try
            {
                string filename = Guid.NewGuid().ToString();
                string contianername = blob.Container.Name;
                string blobname = blob.Name;

                if (contianername.Length > 50)
                {
                    contianername = contianername.Substring(0, 49);
                }
                if (blobname.Length > 50)
                {
                    blobname = blobname.Substring(0, 49);
                }
                filename = filename.Substring(0, 8);
                filename = filename+"_" + contianername + "_" + blobname;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    filename = filename.Replace(c, '-');
                }

                using (var fileStream = System.IO.File.OpenWrite(LocalDownloadPath + "/" + filename))
                {
                    blob.DownloadToStream(fileStream);
                }
                return filename;
            }
            catch(Exception e)
            {
                Alerting.ErrorLogging.WriteTo_Log("Failed Download Blob", e.ToString());
                return "N/A";
            }
        }