gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:52:57 24 4
gpt4 key购买 nike

我有一个 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/

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