将CSV文件写入C:\ temp,从通用Windows应用程序运行Windows 10 IoT

问题描述 投票:0回答:1

当Raspberry Pi 3(运行Windows 10 IoT)无法将数据发送到Azure数据库时,我一直在编写一个需要将一些数据转储到c:\ temp \ TempData.csv的应用程序。

到目前为止,我已经能够使用Windows Powershell创建文件夹和文件,但是当我尝试从应用程序将数据保存到文件时,我只得到“System.UnauthorizedAccessException:访问路径'C:\ temp'是在System.IO.WinRTIOExtensions上被拒绝了,从这个错误中我们正在讨论权限,但我已经尝试更改该文件夹的ACL:get-acl“c:\ temp”将返回“temp BUILTIN \ Administrators每个人都允许FullControl ...“,因此它应该拥有所有必需的权限。

从应用程序的一侧,这是我应该将数据发送到文件的代码:

public static async void SaveFileAsync()
    {
        string File = @"c:\temp\TempData.csv";

        for (int i = 0; i < 50; i++)
        {
            var DataPoint = new SensorData
            {
                Temp = GetNewRandom(22, 40),
                Humidity = GetNewRandom(25, 30),
                Pressure = GetNewRandom(90000, 110000)
            };

            await WriteCSVLine(File, DataPoint);
        }
    }

    private static Task WriteCSVLine(string FilePath, SensorData data)
    {
        try
        {
            using (StreamWriter w = File.AppendText(FilePath))
            {
                return w.WriteLineAsync(data.ToString());
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
            throw;
        }

    }
c# csv permissions raspberry-pi3 windows-10-iot-core
1个回答
1
投票

以下是关于MSDN论坛上File Access on Windows IoT Core的一般性讨论。对于这个问题,您需要使用FolderPermissions工具为UWP应用程序创建一个文件夹。请尝试在PowerShell中运行以下命令。使用您的密码对我来说很好。

FolderPermissions c:\temp -e
© www.soinside.com 2019 - 2024. All rights reserved.