Same File operation not permitted. Access to path denied, Silverlight 5.0 - silverlight

I am working with a silverlight application, File.WriteAllText is giving File operation not permitted when trying to write to local desktop. Access to path exception.
This code always works on local desktop but, is giving error when code is deployed on server.

Silverlight does not have the access priveleges like u expect. If you want to add a file to your Silverlight Application at runtime, you will need to have Silverlight running Out of the Browser with Elevated priveleges. There are certain limitations to this too. You can only access files in Special Folders like My Documents, Pictures, Music etc. For more info, see this and this

Related

UWP on Windows 1903 broadFileSystemAccess access denied on Drive D

broadFileSystemAccess works as expected when accessing files on Drive C, however, as soon as I try to access files on another Drive, I get access denied
Without broadFileSystemAccess, load a file from the Desktop. Access Denied as expected.
With broadFileSystemAccess, load a file from the Desktop. Access Granted as expected.
With broadFileSystemAccess, load a file from the Drive D. Access Denied not expected.
Dim file = Await Windows.Storage.StorageFile.GetFileFromPathAsync("D:\TestFile.txt")
I should be able to access any drive. My system has 4 drives and a NAS, only Drive C is accessable using broadFileSystemAccess.
What do I need to do to allow my app to access files on other drives; this is the only thing holding me back from porting my WPF apps.
Thanks in advance
I'm going to close this. I updated to the latest patch today and it's fixed. The prompt to ask a user to allow the app file system permissions is still broken (e.g. it doesn't prompt still), but the access to files on other drives is now working.
Additional info: I also created new C# and vb.net apps to test the theory and they work as expected, I then went back to the failing project and it's now working - hence me assuming the patch fixed it.

Path.GetTempFileName causes Access to path '' is denied.in Silverlight

I am have a problem with Path.GetTempFileName with running a Silverlight application. If I install my application to run Out-Of-browser it runs ok. It only fails when I run it locally i.e. In-Browser.
The error is
File operation not permitted. Access to path '' is denied.
I cannot debug my application because of this issue. Can anyone suggest a work around?
The problem is probably no access to where ever Path.GetTempPath is pointing to.
If you have access to say My Documents, you could combine that with Path.GetRandomFileName, or if it's not happening too often, a simple time stamp.
Maybe you could use isolated storage. You could ask to make it a trusted application which would gain you access to the file system but doesn't work in say windows phone.
The GetTempFileName method tries to access the temporary folder which is typically on the C:\ (or whichever letter the main drive has been assigned). For security reasons, in-browser applications aren't allowed local access and that's likely why you're getting an error.

Why a virtualized file system for in-browser trusted-mode SL5 apps?

In Silverlight 5, applications can access the file system without restriction via FileInfo and related classes when running with elevated privileges. Also since SL5, an app can run inside the browser with elevated trust.
However, when running in-browser, all access to the file system appears to end up being routed to a special directory AppData\Local\Microsoft\Windows\Temporary Internet Files\Virtualized\C....
This is a different behavior from running without elevated trust altogether, which throws a SecurityException. Out-of-browser, the behavior is as expected.
Note that in all cases I run the app through visual studio, which is, as far as in-browser support is concerned, all I'm interested in.
Is this desired behavior? Can I change it?

Accessing special folders from Silverlight OutOfBrowser application

Inside my Silverlight 4.0 application (with elevated trust level), I'm trying to access the common templates folder, using the code below:
var folder = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
However, such code throwsSystem.Security.SecurityException:
System.Security.SecurityException was unhandled by user code
Message=File operation not permitted. Access to path '' is denied.
StackTrace:
at System.IO.FileSecurityState.EnsureState()
at System.Environment.InternalGetFolderPath(SpecialFolder folder, SpecialFolderOption option, Boolean checkHost)
at System.Environment.GetFolderPath(SpecialFolder folder)
It seems that accessing any folder besides "My Documents" for the current user would throw this kind of exception - Since the SpecialFolder enum has more values, what are they good for? Is there any way to verify which folder this enum/method looks for, or any other way to access it?
In Silverlight 4, the "My Documents" area and isolated storage are the only two places that OOB apps my arbitrarily read/write from/to. This will change with Silverlight 5, where elevated trust apps will have greater access to disk.
As for why it's there at all, see the remark in the MSDN Documentation:
This type is present to support the .NET Compact Framework infrastructure in Silverlight for Windows Phone, and it is not intended to be used in your application code.
It's worth noting that if you are targeting windows OOB, it is possible to read/write files arbitrarily on disk using COM automation and Scripting.FileSystemObject in Silverlight 4:
using (dynamic fso = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
{
dynamic file = fso.CreateTextFile(#"C:\tmp.txt");
file.WriteLine(#"I just wrote to c:\ !!");
file.Close();
}

WPF app won't run in kiosk mode

I have a WPF application that is designed for a touchscreen kiosk. Users will not have access to a keyboard or mouse. The application runs fine when started normally from the program icon in windows. However, when it is set up to run automatically at startup (by replacing the Windows shell using a registry key), the application does not function properly.
The application reads an XML file that lists available videos, then displays buttons to show the videos. When run in "kiosk mode," it does not seem to have access to the files in its media directory (the XML file and presumably the videos as well). I suspect that because the application is running in place of the windows explorer, it is missing resources it needs for file access that are normally loaded by windows explorer.
I have not been able to find any info on this - there is plenty of info on how to get an app to run at startup, but not much on how to make sure it will actually function in that environment. The PC is running Windows 7 Professional.
Is my assumption about the problem correct, or is it likely something else (e.g. permissions - we checked the permissions, but maybe they operate differently when you replace the windows shell?) If it is because needed resources are not loaded, does anyone have pointers on how to make sure my app loads them?
Perhaps you have file access occurring via a file dialog? This might explain a bit further. What is the minimum functionality needed to create Shell Replacement for Windows?
because you have stopped windows default running explorer.exe , your program can not get access to default xml directory therefore you should specify the complete path for example like below:
stream = File.Open(#"C:\x86\Debug\xml.xml", FileMode.OpenOrCreate);

Resources