简体   繁体   English

UWP写入CSV文件

[英]UWP Write to CSV file

I'm trying to write down my dataset into a csv file with the following code 我正在尝试使用以下代码将数据集写到一个csv文件中

 const string filePath = @"F:\train\data.csv";

  foreach (var i in _trainingList)
        {
            var newLine = string.Format("{0},{1},{2}", i.Item1, i.Item2, i.Item3);
            _csv.AppendLine(newLine);
        }
  Task.Run(() =>
        {
            //TODO unauthorized exception
            File.WriteAllText(filePath, _csv.ToString());
        });

I get an System.UnauthorizedAccessException , I have checked that the file allows reading and writing. 我得到了System.UnauthorizedAccessException ,我检查了文件是否允许读写。

Is the problem arising because I'm using UWP platform and does not support the operation. 是否出现问题是因为我使用的是UWP平台并且不支持该操作。 or is my code erroneous? 还是我的代码错误?

You can only access files in the user's Download folder that were created by your application. 您只能访问应用程序在用户的“下载”文件夹中创建的文件。 It's likely that F:\\train is not that folder. F:\\train可能不是该文件夹。

See this MSDN article for what folders a UWP (or Windows Store) app can access: https://msdn.microsoft.com/en-us/library/windows/apps/mt188700.aspx 请参阅此MSDN文章,以了解UWP(或Windows应用商店)应用程序可以访问哪些文件夹: https : //msdn.microsoft.com/zh-cn/library/windows/apps/mt188700.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM