Windows应用商店应用无法附加文字

时间:2015-06-20 14:05:48

标签: windows string append text-files

我正在使用以下代码将文本文件中的所有行读取到数组中,然后检查该行的前4个字符,如果它等于将该行写入不同文件的内容。

        StorageFolder storageFolder = KnownFolders.PicturesLibrary;
        String FileName = "APP DataFile.csv";
        int correct = 0;
        var file = await storageFolder.TryGetItemAsync(FileName) as IStorageFile;
        var lines = await FileIO.ReadLinesAsync(file);
        foreach (string line in lines)
        {
            correct += 1;
        String tempf = line.Substring(0, 4);
        pageTitle_Copy.Text = tempf;
            if (tempf == "Ebbs")
            { writetofile("DataFile_SWANSCOMBE.csv", line); }
            else { };
    ____________________________________________________________________________
      private async void writetofile(String FileName, String tempfi)
    {
        StorageFolder storageFolder = KnownFolders.PicturesLibrary;
        String BodyText = tempfi + Environment.NewLine;            
        StorageFile sampleFile = await storageFolder.CreateFileAsync(FileName, CreationCollisionOption.OpenIfExists);
            await FileIO.AppendTextAsync(sampleFile, BodyText);

    }

似乎工作正常,但我不断收到以下错误

mscorlib.dll中发生了'System.UnauthorizedAccessException'类型的异常,但未在用户代码中处理

其他信息:访问被拒绝。 (HRESULT异常:0x80070005(E_ACCESSDENIED))

BodyText =“Ebbsfleet学院,第二阶段,一楼,GT教室,172,726670 - 插座不适合中继孔明显请安全和修理,Ebbsfleet-26-05-2015-11-31-01。 jpg \ r \ n“字符串         CreationCollisionOption.OpenIfExists = OpenIfExists Windows.Storage.CreationCollisionOption         FileName =“DataFile_SWANSCOMBE.csv”字符串 + sampleFile = {Windows.Storage.StorageFile} Windows.Storage.StorageFile + storageFolder = {Windows.Storage.StorageFolder} Windows.Storage.StorageFolder + this = {HCP1.SplitPage1} HCP1.SplitPage1

问题是,当我查看它试图写入的文件时,已经成功地写了一些行,有时两行然后崩溃有时3行,有时甚至是0行

该文件不是只读的

有什么想法吗?

标记

0 个答案:

没有答案