如何在运行Windows 10 IoT的raspberry pi上上传和读取文件

时间:2017-08-14 23:44:59

标签: c# raspberry-pi3 windows-10-iot-core

我已经构建了一个应用程序来读取配置文件并根据xml加载字典。 我想要的是不需要将该文件添加到程序中。相反,我希望能够上传到pi3,然后告诉程序刷新并读取我上传的文件。它将代码中包含的文件加载到一个不起眼的文件夹中 如何上传代码中的路径并将其指定到更容易访问的文件夹中。

提前致谢

1 个答案:

答案 0 :(得分:1)

使用 Windows.Storage 命名空间,并按照以下代码在UWP上的文件夹和文件中创建,访问和执行此类操作。

            //Get Installation Folder for current application
            StorageFolder rootFolder = ApplicationData.Current.LocalFolder;

            //Create a folder in the root folder of app if not exist and open if exist.
            StorageFolder Folder = await rootFolder.CreateFolderAsync(yourFolderName, CreationCollisionOption.OpenIfExists);

            //Craete a file in your folder if not exist and replace it with new file if exist
            StorageFile sampleFile = await Folder.CreateFileAsync("samplefile.xml", CreationCollisionOption.ReplaceExisting);

            //Create your text and write it on your configuaration file
            string yourText = "Your Sample Text or Configuration";
            await Windows.Storage.FileIO.WriteTextAsync(sampleFile, yourText);

之后,您可以再次访问该文件,从该表单ReadTextAsync方法读取您的配置值。

            //Read data from file
            await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
相关问题