Xamarin.Mac OS X App File.WriteAllText error [duplicate] - c#

The application will be located in /Applications.
The application will be downloaded via a web browser and not via the App Store.
The language being used is Tcl/Tk.
A. Will this work on all versions of OS X 10.5 or higher?
B. Is there a better place to store application files?

~/Library/Application Support is a way better place to store your files:
Use this directory to store all app data files except those associated
with the user’s documents. For example, you might use this directory
to store app-created data files, configuration files, templates, or
other fixed or modifiable resources that are managed by the app. An
app might use this directory to store a modifiable copy of resources
contained initially in the app’s bundle. A game might use this
directory to store new levels purchased by the user and downloaded
from a server.

A. No, generally you should not alter the application bundle once installed. You will very likely encounter permissions or code signing issues if you do.
B. ~/Library/Application Support/MyApp/

Related

.NET Core service/daemon appsettings.json location (user folder or ProgramData)

I have a Windows service that runs as a specific user (agent installed on desktop machines) - I had originally stored/updated appsettings.json in Program Files alongside the binary, but this causes issues during updates etc.
I have since moved to using an app config file under the users home directory - which I create manually (Finding local users profile path in C# and creation of folder).
I also see there is a ProgramData enum that is available via .NET directory enums, and would save the above code (less things to break in future).
The Linux/MacOS version of this software would be under /home/myuser or /etc/myapp. I need to consider this as I write an abstraction layer to run my BackgroundWorker as a daemon and the associated installation thereof.
My question is which is better to follow for this multi-platform supported app, store config files by user directory, or program data directory?
Appreciate this is on the fringes of development question, but also not necessarily serverfault question - if better suited let me know and will repost on a different site.

Windows Forms, Microsoft OneDrive and Settings.Settings class

I have a Windows forms application that uses Application settings using the .NET settings class.
Typically I have a setting such as WindowXSize which is loaded when the program starts, and saved when it ends as follows:
Properties.Settings.Default.WindowXSize = 400;
Properties.Settings.Default.Save;
On load it is just the reverse.
Now this works fine and I have thousands of users with no issues. However, if someone has configured MicroSoft OneDrive to replicate their documents folder, the values never change even if the window is resized.
Not only that, the software can also allow users to save various files in a folder of their choice. Most of the time this is in the documents folder (or subfolder of it). To make sure I get the correct location of the Documents folder I have the following:
path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
This always returns the typical c:\users\userid\documents folder even if OneDrive is syncing the documents folder. The user can then save the file and there are no errors. However, if the user then tries to load it, the file is not found. So it would seem that OneDrive is completely ignoring the .NET mechanisms for Application settings and file IO.
Is there any work around for this? Or am I doing something wrong?
Note that I refuse to load up OneDrive for my documents on my development machine so as to avoid all these issues as well as many others that exist.
Thanks, Tom
Did you change the directory, where your application stores the user settings?
Default is:
"User settings are saved in a file within a subfolder of the user’s local hidden application data folder." 1
Normally OneDrive does not synchronize this hidden AppData folder. Therefore your question makes little sense. Please add more information.

How to Play Video File On D Drive In WinRT?

Using XAML C# in Windows "Metro" Apps how do I go about playing a certain video file. Examples:
D:\video1.wmv
\\MEDIAPC\video2.wmv
The only way I managed to get this working so far is by using FilePicker, but I don't want to use this as I already have a list of files to play.
I have tried to use GetFileFromPathAsync but I keep getting permission / access issues
await StorageFile.GetFileFromPathAsync(#"D:\video1.wmv");
Apologies if this has been answered I just couldn't find an answer that fits my problem.
If your D:\ drive is a non-network resource try adding the Removable storage application capability. This can be accomplished by double-clicking on the Package.appxmanifest and navigating to the Capabilities tab. By default your application (assuming it is a Windows Store app) only has access to local files packaged with your app or files stored in local/roaming/temp folders (usually reserved for Application state).
If your data is stored on a Network resource that requires authentication you will want to enable the Enterprise Authentication capability.
You may also want to fiddle with the Home and Work Networks for the \MEDIAPC\ files if you aren't accessing resources that require network authentication.
Further Reads:
Accessing data and files
How to load data from files
App Capabilities Overview

How can I save multiple files locally in Silverlight?

My problem is I have a LOB application that can possibly save multiple files (number of files only known at runtime) based on user inputs. Saving this as a single file and having the user break them apart, or zipping them up as a single file is not an option unfortunately.
SaveFileDialog seems suited to only save 1 file at a time. Third party controls may be an option but I have yet to find any that serve this purpose. Thanks!
The browser security model guidelines (outside of Silverlight) prohibit web application logic (script or otherwise) from having direct access to the local file system.
Consider what havoc a malicious web site could wreak on your computer if web application script could write arbitrary files to arbitrary locations on the local hard disk!
For this reason, Silverlight isolates your code away from the local file system. Silverlight manages the Open File or Save File dialogs, but your web app code never gets to see the full path of the file names directly for security reasons. The Silverlight dialog only supports working with one filename / path at a time.
Silverlight does offer isolated storage on the local machine in which your web app could write multiple files. However, as noted in comments, isolated storage is isolated in both directions - it keeps the web app isolated from the local file system, and that makes it difficult for the end user to access the contents of the isolated storage outside of the browser. (Difficult enough to make it infeasible for nontechnical users, but not difficult enough to call isolated storage "secure" from malicious snooping).
Short of writing your own native executable browser extension (for each different browser brand and version you wish to support) (or non-sandboxed javascript plugin for some browsers), I don't think there is a way for a web app to push data into multiple local files convenient to use outside of the browser in one user action.
Since this is an LOB in the intranet zone have you considered asking your users to install the app as OOB with Elevated trust. This would allow you to write files to the users Documents folder without the SaveFileDialog.
The other option is to zip the files with a single SaveFileDialog call.
There are no other Silverlight oriented solution.

C#: Create a virtual drive in Computer

Is there any way to create a virtual drive in "(My) Computer" and manipulate it, somewhat like JungleDisk does it?
It probably does something like:
override OnRead(object sender, Event e) {
ShowFilesFromAmazon();
}
Are there any API:s for this? Maybe to write to an XML-file or a database, instead of a real drive.
The Dokan Library seems to be the answer that mostly corresponds with my question, even though System.IO.IsolatedStorage seems to be the most standardized and most Microsoft-environment adapted.
Depending on what type of virtual drive you wish to build, here are some new OS API recently introduced in Windows, macOS and iOS.
Some of the below API is available as managed .NET code on Windows but many are a native Windows / macOS / iOS API. Even though, I was able to consume many of the below API in .NET and Xamarin applications and build entire Virtual Drive in C# for Windows, macOS and iOS.
For Remote Cloud Storage
On Windows. Windows 10 provides Cloud Sync Engine API for creating virtual drives that publish data from a remote location. It is also known under the “Cloud Filter API” name or “Windows Cloud Provider”. Here are its major features:
On-demand folders listing. Folder listing is made only when the first requested by the client application to the file system is made. File content is not downloaded, but all file properties including file size are available on the client via regular files API.
On-demand file content loading. File content can be downloaded in several modes (progressive, streaming mode, allow background download, etc) and made available to OS when application makes first file content reading request.
Offline files support. Files can be edited in the offline mode, pinned/unpinned and synched to/from the server.
Windows shell integration. Windows File Manager shows file status (modified, in-sync, conflict) and file download progress.
Metadata and properties support. Custom columns can be displayed in Windows File Manager as well as some binary metadata can be associated with each file and folder.
On macOS and iOS. MacOS Big Sur and iOS 11+ provides similar API called File Provider API. Its features are similar to what Windows API provides:
On-demand folders listing.
On-demand files content loading.
Offline files support.
File Manager Integration. In macOS Finder and iOS Files application you can can show file status (in the cloud, local).
I am not sure currently if files/folders and can show custom columns in macOS Finder and store any metadata.
For High-Speed Local Storage
On Windows. Windows provides ProjFS API. Its main difference from the Cloud Sync Engine API and macOS/iOS File Provider API is that it hides the fact that it is a remote storage. It does not provide any indication of the file status, download progress, ets. The documentation says it is intended for “projecting” hierarchical data in the form of file system.
You can use the Dokan library to create a virtual drive. There is a .Net wrapper for interfacing with C#.
Yes, use the classes in System.IO.IsolatedStorage
The contents of My Computer can include Shell Namespace Extensions. These COM objects run inside the main Explorer process, as do many other shell extensions. Using C# for such extensions is a bad idea, since your extension cannot control which CLR version Explorer.exe can use. And Microsoft allows only one CLR per process.

Categories

Resources