How access VM file share from Azure Function app

Nuwan Wickramanayaka 81 Reputation points

Hi all

I am having VM file share and needs to read files by using Azure function app. All are in same network (app service ) .

I am trying to access file using path \\pdf_directory\sample.pdf" and trying to the get the file size

FileInfo fileInfo = new FileInfo(filename);
fileLength = fileInfo.Length;

It gives error "unauthorized access when accessing file". Still I couldn't find any reason for that. Let me know how to resolve this issue ?


Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,200 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,484 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,544 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Carlos Solís Salazar 17,426 Reputation points MVP

    Hi @Nuwan Wickramanayaka

    Thank you for asking this question on the **Microsoft Q&A Platform. **

    Assuming that the Azure Function is in the same virtual network as the VM (If not check this documentation

    The reason is that the Function App does not have permission to access the VM,

    A way to authenticate is via Automation Account

    Depending on the language that you are using in your Function you can authenticate in your VM in diverse ways

    Hope this helps!


    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
    NOTE: To answer you as quickly as possible, please mention me in your reply.

  2. Roderick Bant 2,051 Reputation points

    Hi @Nuwan Wickramanayaka

    your question seems to have elements similar to this question on accessing on premise file shares from an Azure Function App. @ajkuma 's answer there indicates that the Sandbox environment restricts outgoing SMB ports.

    In a similar question and answer @ChaitanyaNaykodi-MSFT suggests using a logic app to handle interactions with the file share and connecting the logic app to the function app. The extra logic app may not be the most elegant solution, but it will be an effective and supported means to get the results you need .

    0 comments No comments