Search code examples
c#wpffile-writingscreensaver

How to write a file in WPF for Windows Screen Saver


I developed a custom screen saver in WPF (with the extension .scr) but I got an issue : When screen saver is run by Windows, the application stop imediately. After some tests, I found that it comes from the fact that I'm creating/writing files.

I tried :

  • to add a manifest to run as administrator
  • name my file with 8 characters + 3 for extension
  • write my file in different location ("C:\", "C:\Windows", "C:\Program Files (x86)",...)

But nothing works...

Any idea ?

Note : I need to write lot of lines in my file


Solution

  • Ok, my bad... I found where were my problemss.

    First, screen saver does not have permission to write in Windows folder.

    Then, I was trying to write in a special folder using Environment.SpecialFolder.MyDocuments but this property return the name of the folder. So I need to use Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) instead.

    Finally, I was trying to write a file in a folder that didn't exists. I thought that the folder would be created automatically but I was wrong...

    As suggested by @elgonzo, I have added exception handler and displayed the error messages in a message box using MessageBox.Show(log).