c# - 将文件保存到 Azure Functions 中的临时位置

标签 c# azure azure-functions

我有一个 Azure 函数,我正在尝试将 .xlsx 文件保存到临时文件夹。我的代码在本地运行,但是当我发布到 Azure 时,我收到一条错误消息。

string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\temp\";
string tempFilename = "abc.xlsx";
string pathTradeRecFile = Path.Combine(projectDirectory, tempFilename);

我的错误消息。 <--- 访问路径“C:\Program Files (x86)\SiteExtensions\temp\abc.xlsx”被拒绝。

有人可以告诉我如何将此文件保存在某个地方吗?我在结构中创建了一个名为“temp”的文件夹作为一种可能的解决方案,但我似乎无法访问它。

任何帮助将不胜感激!!

最佳答案

请不要在 Azure Functions(或实际上任何地方)中使用类似 Environment.CurrentDirectory 的内容来获取临时文件夹。请改用 .NET 原生方法来执行此操作:

Path.GetTempPath()

所以最好使用这样的东西:

string pathTradeRecFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".xlsx");

关于c# - 将文件保存到 Azure Functions 中的临时位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65712009/

相关文章:

sql - 在 Java 中的 SQL Azure 报告上进行表单例份验证登录

c# - Azure Function v2 和连接字符串

c# - Webform 中的 HTML 助手?

azure - 每个 VM/NIC 的 Terraform Azure

c# - 为什么不能推断出这些泛型类型?

c# - 错误: Package 'Microsoft.Azure.WebJobs.Extensions' is incompatible with 'all' frameworks in project '

azure - 使用 Azure Function App 在 Python 脚本中使用 SendGrid 发送邮件

Azure Function 应用程序定期不会在触发器或计时器上触发

c# - DetailsView 的事件 "ItemUpdating"中的 OldValues 集合始终为空

c# - WebAPI,将一个或集合对象发布到同一操作而不更改消息正文