Viveka
Viveka

Reputation: 360

How to get the path of folder in Azure Function C#

I have created 2 folders in my project named TempFile and TempFile\Sample. Here is the folder structure

here

How can I get the path of this folder and the file SampleExcel.xlsx (project\TempFile and project\TempFile\Sample\SampleExcel.xlsx resp) using c#. Also once I publish it to Azure will I need to change it?

Here is what I have tried:

public void Run([QueueTrigger("my-queuename", Connection = "")] string myQueueItem, ILogger log)
{    
    //Method 1            
    var dir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
    //Method 2
    var path = Environment.CurrentDirectory;
    //Method 3
    var filePath = Path.GetFullPath(@"TempFile\Sample" + "\\SampleExcel.xlsx");           
} 

The problem with these methods is that they return the path project\bin\Debug\netcoreapp3.1

How can I get the required path?

Any suggestions?

Upvotes: 5

Views: 4792

Answers (1)

Nivi
Nivi

Reputation: 111

Use Environment.CurrentDirectory as:

filePath1 = Environment.CurrentDirectory +"\\TempFile\\" + tempFile + ".xlsx"; 
filePath2 = Environment.CurrentDirectory +"\\TempFile\\Sample\\SampleExcel.xlsx";

Upvotes: 5

Related Questions