0

I wrote a service running in an Azure Windows Server 2016 VM. When it gets a job from the queue it spawns another program which generates a PDF and saves it to disk. I am reading config files and saving HTML files (which are converted to PDF using a third party component) to disk using streamreader/streamwriter.

But I keep getting versions of path could not be found errors for all disk access to the Azure Files SMB share. If I use a local disk it works fine.

I have double checked that it is using the right path and that the path actually exists (simply P:).

This has been running fine for years on a colocated app server. I am trying to move everything to Azure right now.

Any ideas what I am missing or doing wrong?

EDIT:

Looks like I am running into this problem: https://serverfault.com/questions/177139/windows-service-cant-access-network-share

But I can't perform the same solution here because with Azure Files there is no remote server that I can add a user to.

An MSDN forum user suggested using Azure Storage Client Library. My third party PDF component cannot be reprogrammed to use the Azure Client Storage Library, so I am left with doing all of my work on the local drive and then copying the final PDF file over to Azure Files.

This would be a completely acceptable solution. But I don't know how to pull it off.

Brad Mathews
  • 1,567
  • 2
  • 23
  • 45
  • Please edit your question to show some detail (like your code, the actual share config, etc). Without seeing any details, you'll only get guesses. – David Makogon Oct 12 '17 at 03:18
  • What do you mean exactly with "service running on a Windows server"? A Windows Service or a web application exposing a web service? Another point: I understood that P: is a mapped network share. Under which user you created the mapping? Is the the same user under which the service run? Also add information/full stack trace about the error you got – Fabrizio Accatino Oct 12 '17 at 05:51

1 Answers1

0

You can't do "normal" file access to an Azure Files SMB share from a service or a program spawned from a service. You can copy files to and from your storage account to a local drive programmatically. You have to use a local drive to create and edit files and then copy those back to your storage account.

Here is some VB.Net code to copy a local file to an Azure Files Share (works but it not cleaned up):

Imports Microsoft.WindowsAzure.Storage
Imports Microsoft.WindowsAzure.Storage.File
Imports System.Configuration

    Dim StorageAccount As CloudStorageAccount
    Dim file As FileInfo
    Dim fileClient As CloudFileClient
    Dim share As CloudFileShare
    Dim root As CloudFileDirectory
    Dim dir As CloudFileDirectory
    Dim cloudFile As CloudFile

    Try
        file = New FileInfo(InFileName) ' includes full path to file
        StorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings.Get("AzureFilesConnString"))

        fileClient = StorageAccount.CreateCloudFileClient()
        share = fileClient.GetShareReference("sharename")
        root = share.GetRootDirectoryReference()
        dir = root.GetDirectoryReference("PDFs") ' Note that you apparently can't copy to the root (\) folder 

        cloudFile = dir.GetFileReference(OutFileName) ' Only the file name, not full URI

        Using fs As FileStream = file.OpenRead()
            cloudFile.UploadFromStream(fs)
        End Using
    Catch ex As StorageException
        Debug.Print(ex.Message)
        Debug.Print(ex.RequestInformation.Exception.ToString)
    Catch ex As Exception
        Debug.Print(ex.Message)
    End Try
Brad Mathews
  • 1,567
  • 2
  • 23
  • 45
  • "You can't do "normal" file access to an Azure Files SMB share from a service or a program spawned from a service." Is this documented anywhere? – Brandon Silva Aug 09 '18 at 17:30