locked
FileIO::WriteTextAsync is setting files to hidden

    Question

  • Greetings,

    We are experiencing some strange behavior with file i/o on certain machines.  Multiple, consecutive writes to the same file will cause the file's "Hidden" property to get set by the OS.  We have tested this code to run on two different Windows phones, one Surface tablet, two Windows 8.1 VMs and one Windows 8.1 dedicated machine.  Of all these machines, the only one that is having issues is the Windows 8.1 dedicated machine.  This machine is the most performant of the ones we tested with.  I can't imagine there is an OS setting causing this behavior.  

    Below is code that we can run in a new, standalone Windows Store Universal (c++) project to reproduce the issue:

    ...
    
    #include <ppltasks.h>
    using namespace concurrency;
    using namespace Windows::Storage;
    using namespace Windows::Storage::Streams;
    
    ...
    
    void App::OnLaunched(LaunchActivatedEventArgs ^e)
    {
        ...
        // write to file 1000 times in a loop, the file will eventually set itself to hidden
        create_async([]() {
    	String ^fileName = "plzdonthideme.txt";
    	auto folder = ApplicationData::Current->LocalFolder;
    	StorageFile ^file = create_task(folder->CreateFileAsync(fileName, CreationCollisionOption::ReplaceExisting)).get();
    
    	for (int i = 0; i < 1000; i++) {
    		try {
    			create_task(FileIO::WriteTextAsync(file, "bacon ipsum...", UnicodeEncoding::Utf8)).wait();
    		}
    		catch (COMException ^e) { }
    	}
        });
    }

    After running this app, the file "plzdonthideme.txt" will be hidden.

    Is this a bug, or is there something we can do to prevent this behavior?  Thanks.

    -steveb

    Wednesday, January 14, 2015 6:34 PM

Answers

  • You do not have control over the file attributes since your Windows Store app does not interact with the file system directly. There is no programmatic workaround to get around this security model.

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by -steveb Monday, January 19, 2015 8:05 PM
    Thursday, January 15, 2015 10:57 PM
    Moderator

All replies

  • Please see this thread about a similar problem which could happen with Realtime file monitoring software which can contribute to such type of issues:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/0127a71e-1e42-41ae-b9a6-71c0357d39fd/fileio-appendtextasync-sets-hidden-attribute-on-file?forum=winappswithhtml5

    The hidden attribute gets set (and is supposed to get reset) by the runtime broker process who is performing the "brokered" write to the file system since your app does not directly interact with the file system.  


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Wednesday, January 14, 2015 11:16 PM
    Moderator
  • Thanks for the response @Prashant.  

    Since we can't interact with the hidden file via the broker, is there a clear recovery path?

    Thanks in advance.

    -steveb


    • Edited by -steveb Thursday, January 15, 2015 12:04 AM
    Wednesday, January 14, 2015 11:53 PM
  • You can probably check with your antivirus/ file monitoring software vendor and check to see if they have a way to bypass the filtering of files and excluding the "*.~TMP" file extension.

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Thursday, January 15, 2015 12:16 AM
    Moderator
  • I am providing a library that our customers will use in their products, and won't have access to any of the 3rd party software settings on their customers' machines.  

    I was hoping there would be a programmatic way to get around this.  Is that possible?

    Thanks.

    -steveb

    Thursday, January 15, 2015 5:49 PM
  • You do not have control over the file attributes since your Windows Store app does not interact with the file system directly. There is no programmatic workaround to get around this security model.

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by -steveb Monday, January 19, 2015 8:05 PM
    Thursday, January 15, 2015 10:57 PM
    Moderator
  • Thanks for the help, Prashant.
    Monday, January 19, 2015 8:06 PM