Can I read files inside a directory without using OpenFileDialog? - c#

I have an app and I am thinking that a WPF XBAP app would be best suited for this. However, I am not aware of the limitations that it comes with. So, before choosing this tool I need to be aware of it.
Basically I want to read any folder inside the OS and get listing of files inside that folder. Is this possible using WPF XBAP?

OpenFileDialog is just a media that makes selection & reading easier. You can read any folder as long as you know path & have permission to read the folder.

Related

Uwp Cannot List or access .lnk or url files

Before I get into further details I wanted to point out that uwp can now know have system wide file access so this issue is not exactly related to that.
With that out of the way, the issue is rather simple to explain, uwp cannot query or access link (.lnk) or weblink files as well as possible other files that I dont know yet.
To be more specific the tools found both in the System.io and the Windows.Storage namespaces are incapable of listing .lnk and url files.
They simply never appear on Queries like the System.IO.Directory.GetFiles
StorageItemQueryResult.GetFiles()
While also direct access from path as allowed by functions like
StorageFile.GetFileFromPathAsync() or System.IO.File.Open()
will cause System.UnauthorizedAccessException: Access is denied.
I am posting knowing full well that this will probably never be answered, the only glimmer of hope is the fact the hidden build in uwp explorer can indeed list the affirmational files.
The .lnk file type has limitation to be accessed from UWP app since UWP app's sandboxed and user permission. You can not access this file type from path even using the broadFileSystemAccess Capability. But you can get the file by FileOpenPicker which lets the user choose and open files.

How to use image without making .exe heavier c#

How to use image without making .exe file heavier in c# windows application.
One way is keeping the file in debug folder and reading it at runtime but i dont want the user to see any images in the debug folder.
How can i achieve this?
You could store images in a separate Class Library and then reference it in your application.
Users wouldn't be able to see the image files this way, instead they would be stored as a dll file in your debug folder.
Edit:
I have recorded the actions required to achieve this setup, check out this link:
https://www.youtube.com/watch?v=8i794GmZ_aI

"GodMode" folder contents c#

I am currently building an application that will need to use all of the Control Panel's shortcuts which can be found in "shell:::{ED7BA470-8E54-465E-825C-99712043E01C}" aka GodMode folder.
However, when I try to access the folder through code, I get no result. This also happens when I try to enumerate the files using the command prompt (using 'dir').
Any help is appreciated.
Thanks
The God Mode is implemented in the Windows Explorer Shell. If you look at it at the file system level it's just an ordinary folder with a peculiar name. That's why you won't see anything special in it when reading it as a directory in code. If you look at it with the command prompt it's the same - just a plain empty folder with a peculiar name.
You won't be able to access the shortcuts through the file system API, so you have to look for an API that exposes the control panel contents instead.

.net WPF application create a secure folder

I am working on one desktop application which is built by using .net WPF. I have some data inside the application like images,videos..
I want to make this folder secure, so nobody can access the data inside the folder after application installation. Only the application can read the data from that directory.
Even though administrator of that machine can not open that folder to check the content.
Is it possible to have this kind of security inside the WPF application.
Only motive it to keep the sensitive data protected from external copy from the application users.
Thanks,
Vijay
It depends on how you use the resources.
Actually you could encrypt all "protected" files, so that after the installation every one can copy but no one can use them unless your application decrypts the files.
When you encrypt files you should definitively test the performance (decryption takes some time).
Two links showing how you could do it:
What's the easiest way to encrypt a file in c#?
http://lukhezo.com/2011/11/06/encrypting-files-in-net-using-the-advanced-encryption-standard-aes/
Add the file you would like to strongly protect to you solution. Then right click each file, go to properties and set its "build action" to "embedded resource".
And for how to access the resource stream from within the exe for use with in your application, see link below
How to compile all files to one exe?
That way, your private files will not be copied to the installation folder but will instead reside inside your .exe file.
WPF is beside the point. Applications run with the permissions of the users that start them. If an application needs access to files, then the user will also need rights to those files.
In short, the answer is no, you cannot do exactly what you are asking.
The best you will be able to do is make it hard for a user to discover where the assets are coming from, but you will never be able to give access to your application without giving access to the application's user.

C#: How would you organize a screen saver in the file system?

I am planning to create a screen saver. Thinking of trying out some WPF as well. Anyways, I am not quite sure how I would organize the screen saver on disk in the file system. I have mainly two related issues that I am very uncertain on how to solve:
Normally an application lives, with all its 3rd party assemblies, static resources, images, etc., in the Program Files folder and is run from there. For example C:\Program Files\MyScreenSaver. But (if I haven't missed something) the executable of a screen saver in windows need to have the scr extension and to live in the system folder, for example C:\Windows\System32. How do you program the screen saver so that it can find the "rest of itself"? Would you use the windows registry? Or creat some sort of config file next to the scr file with the path to the rest? And would you make the scr to just be sort of a launcher of an exe in the application folder? Or would this be a bad idea?
I also want the screen saver to download new content from certain places on the internet. But where do I put it, and how does the screen saver find it? If I have understood correctly, an application is not to create new contents in its application folder, but rather in a user folder. How do I find that folder? Do you build it up from environment variables? And in what specific directory should things like this really be in? For example on Vista I see that you have one folder called C:\ProgramData. You also have C:\Users\username\AppData\Local, C:\Users\username\AppData\LocalLow and C:\Users\username\AppData\Roaming. Have also seen a lot of programs dump stuff in the my documents folder (although I hate programs cluttering up my documents folder, so I will probably try to avoid that :p).
What are some best practices when it comes to these issues of laying out your application in the file system? I am want it to be best and "most correct" for Windows 7, which means it will probably work the same in Vista as well (?), but it would also need to work in XP, since a lot of people are using that still.
I'm still using XP :)
System.Environment.SpecialFolders is what you want for these special locations.
Say,
System.Environment.SpecialFolder.LocalApplicationData
For a screen saver I'd try to put most of it in the .exe (.scr) file. It might make the executable quite big but I think it's worth it.
For the downloaded content use application data folder, or maybe allow user to set the location (put the path in registry). For example if you are downloading images, the user might want to put that in My Pictures folder.
You can put it in the System32 (or SysWOW64) folder, but you can also put it in just the Windows folder, which would prevent x86 vs x64 issues.
You can find some other hard to find, but important information about writing screen savers here:
https://github.com/steveniles/MandelZoom/wiki
(Disclosure: I wrote the above wiki as a companion for the source code of one of my own screen savers.)

Categories