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