{"id":5400,"date":"2017-09-25T20:51:51","date_gmt":"2017-09-25T20:51:51","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=5400"},"modified":"2017-09-25T20:51:51","modified_gmt":"2017-09-25T20:51:51","slug":"using-azure-file-storage","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/using-azure-file-storage\/","title":{"rendered":"Using Azure File Storage"},"content":{"rendered":"<p>File storage is pretty much what is says in the tin. It&#8217;s a shared access file system using the SMB protocol. You can create directories, subdirectories and store files in those directories &#8211; yes, it&#8217;s a file system.<\/p>\n<p><strong>Reading a file<\/strong><\/p>\n<p>Using the Azure Portal either locate or create a storage account, within this create a File Storage, then create a share. Within the share upload a file, mine&#8217;s the Hello World.txt file with those immortal words <em>Hello World<\/em> within it.<\/p>\n<p>Let&#8217;s read this file from our client. In many ways the client API is very similar to that used for Blob storage (as one might expect).<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar storageAccount = CloudStorageAccount.Parse(\r\n   CloudConfigurationManager.GetSetting(\r\n      &quot;StorageConnectionString&quot;));\r\n\r\nvar fileClient = storageAccount.CreateCloudFileClient();\r\n\r\nvar share = fileClient.GetShareReference(&quot;myfiles&quot;);\r\nvar root = share.GetRootDirectoryReference();\r\nvar file = root.GetFileReference(&quot;Hello World.txt&quot;);\r\n\r\nvar contents = file.DownloadText();\r\n<\/pre>\n<p><strong>Uploading a file<\/strong><\/p>\n<p>We can upload a file using the <em>UploadFromFile<\/em>. In this example we&#8217;ll just upload to the root folder of the <em>myfiles<\/em> share<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar storageAccount = CloudStorageAccount.Parse(\r\n   CloudConfigurationManager.GetSetting(\r\n      &quot;StorageConnectionString&quot;));\r\n\r\nvar fileClient = storageAccount.CreateCloudFileClient();\r\n\r\nvar share = fileClient.GetShareReference(&quot;myfiles&quot;);\r\nvar root = share.GetRootDirectoryReference();\r\nvar file = root.GetFileReference(&quot;Hello World.txt&quot;);\r\nfile.UploadFromFile(&quot;Hello World.txt&quot;);\r\n<\/pre>\n<p><strong>Deleting a file<\/strong><\/p>\n<p>Deleting files is as simple as, the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar storageAccount = CloudStorageAccount.Parse(\r\n   CloudConfigurationManager.GetSetting(\r\n      &quot;StorageConnectionString&quot;));\r\n\r\nvar fileClient = storageAccount.CreateCloudFileClient();\r\n\r\nvar share = fileClient.GetShareReference(&quot;myfiles&quot;);\r\nvar root = share.GetRootDirectoryReference();\r\nvar file = root.GetFileReference(&quot;Hello World.txt&quot;);\r\nfile.Delete();\r\n<\/pre>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/files\/storage-files-introduction\" target=\"_blank\">Introduction to Azure File storage<\/a><br \/>\n<a href=\"https:\/\/docs.microsoft.com\/en-us\/rest\/api\/storageservices\/file-service-rest-api\" target=\"_blank\">File Service REST API<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>File storage is pretty much what is says in the tin. It&#8217;s a shared access file system using the SMB protocol. You can create directories, subdirectories and store files in those directories &#8211; yes, it&#8217;s a file system. Reading a file Using the Azure Portal either locate or create a storage account, within this create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[96],"tags":[],"class_list":["post-5400","post","type-post","status-publish","format-standard","hentry","category-azure-2"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=5400"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5400\/revisions"}],"predecessor-version":[{"id":5434,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5400\/revisions\/5434"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=5400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=5400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=5400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}