Unable to create a new folder in Azure file share by a Windows service running in Azure VM

392 Views Asked by At

Have a Windows service running in a Azure Windows Server 2022 VM, also mapped the Azure file share to a Windows drive Z:\ in this VM according to this tutorial, the Windows service is trying to create a folder ABC in the Z:\test folder, but it didn't work, how to fix this?

Directory.CreateDirectory("Z:\\test\\ABC");

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

I tried to reproduce the same in my environment and got below results:

I have storage account with one file share named srifileshare like below:

enter image description here

In that file share, I added one directory named test like below:

enter image description here

To map file share to Windows VM, I got Powershell script from here:

enter image description here

When I ran the above script in my Windows VM, it mapped to file share successfully like below:

enter image description here

When I checked the same in File Explorer, Z drive is available with test folder in it like below:

enter image description here

When I tried to create ABC folder inside test folder, it created successfully like below:

enter image description here

I checked the same in Portal where ABC directory is created in file share successfully like below:

enter image description here

Note that, only UNC paths are supported to create a directory on a remote computer or on a share

In your case, try changing the path from Z:\\test\\ABC to below:

Directory.CreateDirectory("\\\\<storageaccountname>.file.core.windows.net\\<storagefilesharename>\\test\\ABC");

Reference:

Directory.CreateDirectory Method (System.IO) Microsoft