【发布时间】:2019-07-20 09:50:19
【问题描述】:
当 Raspberry Pi 3(运行 Windows 10 IoT)无法将数据发送到 Azure 数据库时,我一直在编写一个需要将一些数据转储到 c:\temp\TempData.csv 的应用程序。
到目前为止,我已经能够使用 Windows Powershell 创建文件夹和文件,但是当我尝试从应用程序将数据保存到文件时,我只得到“System.UnauthorizedAccessException: Access to the path 'C:\ temp' 被拒绝。在 System.IO.WinRTIOExtensions",从这个错误中可以清楚地看出我们正在谈论权限,但我已经尝试更改该文件夹的 ACL:get-acl "c:\temp" 将返回 "temp BUILTIN\Administrators Everyone Allow 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