.NET Maui FilePicker results in This platform does not support this file type error for MacOS - .net-maui

I am building a desktop app in .NET Maui which targets Windows and MacOS.
When using the built-in FilePicker on Mac (Catalyst) I get the following error:
{System.PlatformNotSupportedException: This platform does not support this file type. at Microsoft.Maui.Storage.FilePickerFileType.GetPlatformFileType(DevicePlatform platform) at Microsoft.Maui.Storage.FilePickerFileType.get_Value() at Microsoft.Maui.S…}
I have tried multiple file types, including csv, jpg, text/csv but nothing works.
public async Task ImportCSV()
{
try
{
var customFileType = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.WinUI, new[] { ".csv" } },
{ DevicePlatform.macOS, new[] {"csv"} }
});
PickOptions options = new()
{
PickerTitle = "Please select a csv file",
FileTypes = customFileType
};
var file = await FilePicker.Default.PickAsync(options);
if (file != null)
{
string filePath = AppStateService.fixMacFilePath(file.FullPath);
AppStateService.AppState.csvFilePath = filePath;
await InitiateCsvMapping();
}
}
catch (Exception ex)
{
}
}
I am running Visual Studio Community 2022 for Mac Preview
Version 17.4 Preview (17.4 build 715)
The documentation does say that I should "Enable iCloud capabilities" but does not provide any links or other information regarding this. I did some digging, and found some documentation that says that it necessary to do this via the Entitlements.plist file (but there is none in the Maui project) and seems to only be relevant when publishing your app to the App store which I am not during development. I don't even care about iCloud right now. I just want to select a CSV file from my own desktop. Is this the problem? Thanks!!
Here is the article

I don't think it has something to do with ICloud. It is just the wrong file type. File types are different on MacOS.They are called UTypes.
I haven't tried but it is likely:
public.comma-separated-values-text
More Info here: commaSeparatedText
And maybe it is DevicePlatform.MacCatalyst instead of macOs.

Related

Android Studio - prompt to open a downloaded file with any application available

I have an application which receives urls from a server, using Firebase. When the url is received, the file at that url is automatically saved on the local storage (they are gpx files).
But after this, I want my application to prompt the user to open the downloaded file with whatever navigation application they have installed on their phone. Something similar to when you go to the file manager yourself, click on a file, and the system shows you all applications which could open that file, and lets you chose (or opens it directly with your default setting, if you have one).
I have not been able to find anything about this, and searches containing "android studio" and "open file" show mostly tutorials about how to manage the source files themselves, so they are not helpful at all.
You could do something like:
String mimeType = myMime.getMimeTypeFromExtension(fileExt(getFile()).substring(1));
newIntent.setDataAndType(Uri.fromFile(getFile()),mimeType);
private String fileExt(String url) {
if (url.indexOf("?") > -1) {
url = url.substring(0, url.indexOf("?"));
}
if (url.lastIndexOf(".") == -1) {
return null;
} else {
String ext = url.substring(url.lastIndexOf(".") + 1);
if (ext.indexOf("%") > -1) {
ext = ext.substring(0, ext.indexOf("%"));
}
if (ext.indexOf("/") > -1) {
ext = ext.substring(0, ext.indexOf("/"));
}
return ext.toLowerCase();
}
}
This allows you to get the type based on file extension. Then just startActivity passing in the newIntent. This should achieve what you are looking for.

log4net web plugin location of log file

I have a windows forms application that runs in two different modes desktop mode and web plugin mode. I'm trying to put the log files using log4net in the same place. but when it is running as a web plugin my log file get put into the temporary internet folder of the users app data folder.
Code:
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
if (Uri.TryCreate(uri, "log4net.config", out uri))
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(uri.LocalPath));
}
_configured = true;
if (Utilities.WebPlugin)
{
var logNetHierarchy = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
foreach (var iAppender in logNetHierarchy.Root.Appenders)
{
if (iAppender is FileAppender)
{
var fileAppender = (FileAppender)iAppender;
fileAppender.File = #"C:\Users\" + Environment.UserName + #"\Company\Viewer\Web\log.xml";
fileAppender.ActivateOptions();
}
}
}
I would like to get them in the same place without including some kind of script.
stuartd was right soon as I put the site into trusted sites it worked perfectly.

Windows 10 App - File downloading

I am working with Windows 10 universal app and i want to download a file in that. The file link to Sharepoint server. I have passed token in headr to a web service and then service returned byte array to my WinJS.
Now i want to save the file, how can i do this? I tried several code samples but not working.
var folder = Windows.Storage.ApplicationData.current.localFolder;
folder.createFileAsync("document.docx", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
return Windows.Storage.FileIO.writeTextAsync(file, result.response);
}).then(function () {
//saved
});
I am using above code and it is creating new file but no content is placed there. Please suggest what to do.
You never open the file for WriteAccess. I have included code from my working app. First do this command
StorageFile ageFile = await local.CreateFileAsync("Age.txt", CreationCollisionOption.FailIfExists);
then do this:
// Get the file.
var ageFile = await local.OpenStreamForWriteAsync("Age.txt",CreationCollisionOption.OpenIfExists);
// Read the data.
using (StreamWriter streamWriter = new StreamWriter(ageFile))
{
streamWriter.WriteLine(cmbAgeGroup.SelectedIndex + ";" + DateTime.Now);
streamWriter.Flush();
}
ageFile.Dispose();

Access denied using mvxfilestore, mvvmcross annd xamarin touch ios 8.1

My app just got reject from apple and i believe it might be caused by them changing to test with ios 8.1. However I cannot reproduce the error in any way. Their chrash report states the app chrashes on startup.
It seems that the exception(have the crash log) comes from
<Warning> Unhandled managed exception: Access to the path "/var/mobile/Documents/settings" is denied. (System.UnauthorizedAccessException)
which originates from
Cirrious.MvvmCross.Plugins.File.MvxFileStore.WriteFileCommon
I am using the mvvmcross 3.11 MvxFileStore plugin. Deployment target ios7, 8.1 ios sdk.
I have been surfing the web and some states Documents directory has moved in iOS 8 and this might cause the exception.
But I cant wrap my head around the fact that I cant reproduce this error.
Do anyone have a similar issue, a suggestion how to fix or an idea how to reproduce their crash.
Anything is appreciated.
Update:
From the post it is suggested to do the following fix
int SystemVersion = Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]);
if (SystemVersion >= 8)
{
var documents = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;
filename = Path.Combine(documents, sFile);
}
else
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // iOS 7 and earlier
filename = Path.Combine(documents, sFile);
}
I have tried adding it to our project. We used the MvxFileStore to create the path to the settings file
var filestore = Mvx.Resolve<IMvxFileStore>();
string path = filestore.PathCombine(filestore.NativePath (string.Empty), FILENAME);
Now We de the following
var filestore = Mvx.Resolve<IMvxFileStore>();
string path = this.DocsDir() + "/" + FILENAME;
public string DocsDir ()
{
var version = int.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]);
string docsDir = "";
if (version>=8) {
var docs = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User) [0];
docsDir = docs.Path;
Console.WriteLine("ios 8++ "+docsDir);
} else {
docsDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
Console.WriteLine("ios 7.1-- " + docsDir);
}
return docsDir;
}
I will resubmit our app and post the result.
Okay,
The fix we did by seperating ios 8 and the rest of ios and do different implementations depending on the ios worked.
Apple has approved our apps and all is love (y)

SSRS importer in C# 4.0, move reports from one server to another w/o changing format

yes, i know about File.Copy(...), but is there a web service method that can do the same thing? i am also worried about credentials needed to access the server. the inputs are to be the report filepath and the url to the server i want to move the report to WITHOUT CHANGING THE FORMAT. i have been looking at the web service ReportService2005 but not so sure it will work. other web services i have available are: ReportExecution2005, ReportingServices, ReportService, and ReportService2006. i would like to stay away from using rs.exe as well.
// Determine filename without extension (used as name in SSRS)
FileInfo fileInfo = new FileInfo(FileSystemPath);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
try
{
// Determine filecontents
Byte[] fileContents = File.ReadAllBytes(fileInfo.FullName);
// Publish report
rsService.Warning[] warnings = this.rs.CreateReport(fileNameWithoutExtension, this.SSRSFolder, true, fileContents, null);
if (warnings != null)
{
foreach (rsService.Warning warning in warnings)
{
//Log warnings
}
}
}
catch
{
//handle error
}

Resources