Reputation: 360
I have created 2 folders in my project named TempFile
and TempFile\Sample
. Here is the folder structure
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
Reputation: 111
Use Environment.CurrentDirectory
as:
filePath1 = Environment.CurrentDirectory +"\\TempFile\\" + tempFile + ".xlsx";
filePath2 = Environment.CurrentDirectory +"\\TempFile\\Sample\\SampleExcel.xlsx";
Upvotes: 5