简体   繁体   English

C#WP8文件消失

[英]C# WP8 file disappearing

I am saving a creating a file in a folder and writing some data to it like this: 我将创建文件保存在文件夹中,并向其中写入一些数据,如下所示:

        if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\BinarySettings"))
            Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\BinarySettings");

        string settingFilePath = Directory.GetCurrentDirectory() + "\\BinarySettings\\" + setting_Name + ".bindat";
        FileStream binaryFileStream = new FileStream(settingFilePath, FileMode.Create);//If the setting already exists overwrite it otherwise create it
        BinaryWriter binaryWriter = new BinaryWriter(binaryFileStream);

        binaryWriter.Write(setting_Bytes);
        binaryWriter.Flush();

        //Dispose of the streams after we have finished using them
        binaryWriter.Dispose();
        binaryFileStream.Dispose();

        Debug.WriteLine(File.Exists(settingFilePath));

This seems to work fine because using File.Exists on the file after this from anywhere in the application returns true. 这似乎很好用,因为此后从应用程序中任何位置对文件使用File.Exists都返回true。

The strange thing is that when my application starts again and I want to load the data from the file then it has suddenly disappeared. 奇怪的是,当我的应用程序再次启动并且我想从文件中加载数据时,它突然消失了。 Trying File.Exists on the file suddenly returns false. 在文件上尝试File.Exists突然返回false。

Has this ever happened to any of you and what could cause such bizarre behavior? 你们有没有发生过这种情况,什么原因可能导致这种奇怪的行为?

Ok, the problem was that I was actually reinstalling the application instead of relaunching it. 好的,问题是我实际上是在重新安装该应用程序,而不是重新启动它。 To relaunch it you have to do so from the Windows Phone and not Viusal Studion. 要重新启动它,您必须从Windows Phone而不是Viusal Studion进行。

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

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