gpt4 book ai didi

c# - 如何在Azure Function C#中获取文件夹路径

转载 作者:行者123 更新时间:2023-12-05 03:39:49 25 4
gpt4 key购买 nike

我在我的项目中创建了 2 个文件夹,分别名为 TempFileTempFile\Sample。这是文件夹结构

here

如何使用 c# 获取此文件夹和文件 SampleExcel.xlsx(project\TempFileproject\TempFile\Sample\SampleExcel.xlsx resp)的路径.另外,一旦我将它发布到 Azure,我还需要更改它吗?

这是我尝试过的:

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");
}

这些方法的问题在于它们返回路径 project\bin\Debug\netcoreapp3.1

如何获取所需的路径?

有什么建议吗?

最佳答案

Environment.CurrentDirectory 用作:

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

关于c# - 如何在Azure Function C#中获取文件夹路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68450688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com