I have a Xamarin UWP app and am trying to load a file from my current users "Documents" library.
I understand that I need to add a File Type Association declaration first. I've done this and the file icon has changed to my application icon.
In the app I'm then using the FilePicker plugin from here...
https://github.com/ArtjomP/FilePicker-Plugin-for-Xamarin-and-Windows
FileData file = await CrossFilePicker.Current.PickFile();
Byte[] data = file.DataArray;
All I do is browse to the file and select it, but the application crashes with an access violation on the second line.
I've added the following capabilities to my UWP manifest, not sure if they are event relevant anymore.
<uap:Capability Name="documentsLibrary" />
<uap:Capability Name="removableStorage" />
How do I open my files? I ideally need to use a convenient location like the documents library.
Nick.
Edit:
I've followed this article, and still no joy.
https://www.pmichaels.net/2016/11/11/uwp-accessing-documents-library/
You are using a old package which most likely is no longer supported.
Try this one, https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows
It is quite simple, and also supports UWP.
Sample usage
try
{
FileData fileData = await CrossFilePicker.Current.PickFile();
if (fileData == null)
return; // user canceled file picking
string fileName = fileData.FileName;
string contents = System.Text.Encoding.UTF8.GetString(fileData.DataArray);
System.Console.WriteLine("File name chosen: " + fileName);
System.Console.WriteLine("File data: " + contents);
}
catch (Exception ex)
{
System.Console.WriteLine("Exception choosing file: " + ex.ToString());
}
EDIT: I reworded the answer for clarity, and to avoid some implications that #MickyD rightly pointed in comments and I don't agree with those implications either:
This seems like a bug in the package as it doesn't work according to its documentation and one possible thing to do is to submit the issue to GitHub so that the bug is resolved by the developer of the package.
The other possible thing to do is to look for the alternatives. You may try to find other similar packages and see if they work, and the alternative for which I am sure that works is to use the native functions in System.Windows.Storage (as it is officially supported).
Related
I'm trying to build a Flutter project on Xcode with firebase installed. I'm getting the following error: Property 'downloadURL' not found on object of type 'FIRStorageMetadata *'
This is being caused by the following section in the FirebaseStoragePlugin.m file:
NSString *path = call.arguments[#"path"];
NSDictionary *metadataDictionary = call.arguments[#"metadata"];
FIRStorageMetadata *metadata;
if (![metadataDictionary isEqual:[NSNull null]]) {
metadata = [self buildMetadataFromDictionary:metadataDictionary];
}
FIRStorageReference *fileRef = [[FIRStorage storage].reference child:path];
[fileRef putData:data
metadata:metadata
completion:^(FIRStorageMetadata *metadata, NSError *error) {
if (error != nil) {
result(error.flutterError);
} else {
// Metadata contains file metadata such as size,
// content-type, and download URL.
NSURL *downloadURL = metadata.downloadURL; <---------------- This line
result(downloadURL.absoluteString);
}
}];
}
Since I didn't generate this code, I don't particularly want to edit it as it should really be working out of the box. I've tried to change the method to see whether later versions of Firebase might only accept another function but to no avail. What shall I do in this situation? Should I perhaps try to rebuild the project with a higher version of Firebase or is there a one line fix?
The downloadURL was removed from the StorageMetadata class in May 2018. If your native iOS code still uses that, it's high time to find an updated SDK or update your code to match the documentation on uploading a file and getting its download URL.
If you're using the FlutterFire binding libraries, upgrade to the latest version (as I definitely don't see any reference to metadata.downloadURL in its current code base). If you're using another library, check if the latest version of that solves the problem - or otherwise consider switching to the FlutterFire libraries as those are quite actively maintained.
I've spent the last day trying to get a checkbox validator to work. I found some starting code on the 4GuysFromRolla website, however this was coded back in 2006 and doesn't play alongside updatepanels.
I've made changes and now it works. As I'd made quite a few changes I wanted to standardise it and use it alongside other utility classes, so I created a new class project and copied the code verbatim.
The problem is that the original works, but I get a WebResource not found error on my new class project.
The differences are: The original was a web application project:
my new project is simply a class library project.
The original assembly and namespace have changed.
Both contain a single class and a resource file (.js)
Both resource files are contained in the root directory
Both resource files are set to embed resource
I'm running out of ideas, and have exhausted the answers I've found on the web with no success.
Is there an issue with the fact that its a class library? Have I perhaps overlooked something else?
Its pretty difficult to see beyond those 2 questions because the project is so small and insignificant.
Here's the code that does work:
if (this.RenderUplevel && this.Page != null)
{
ScriptManager.RegisterClientScriptResource(Page, this.GetType(), "skmValidators.skmValidators.js");
}
Here's the code that doesn't:
if (this.RenderUplevel && Page != null)
{
ScriptManager.RegisterClientScriptResource(Page, this.GetType(), "ValidationExtender.EvaluationFunctions.js");
}
Anyone give any ideas?
Thanks in advance.
The error turned out to be a mismatch between the dll's in the test page.
I'm developing an ASP.NET webapp that has a multilanguage feature allowing the webmaster to create new languages at runtime.
The approach that I was thinking is the following:
The user selects one available (not created) language.
When the user confirms, the application automatically copies a set of existing resources, replacing the filename with the new culture. For example: default.aspx.en-us.resx to default.aspx.es-ar.resx.
The user edits the recently created resources.
Currently I'm having troubles with step number 2. I've achieved to copy the resources, but then these new resources are ignored. I think that this happens because the new resources are not included in the running assembly, and therefore are being ignored.
When I test the following code in my local project, I would have to manually add the new resources to the solution and then recompile to make it work.
Does anyone know how to make this work?
This is the code of the mentioned copy.
string _dir = path_ + "App_LocalResources\\\\";
DirectoryInfo _dirInfo = new DirectoryInfo(_dir);
foreach (FileInfo _file in _dirInfo.GetFiles("*en-us.resx")) {
_file.CopyTo(_dir + _file.Name.Replace("en-us", idioma_.Cultura));
}
string _dir2 = path_ + "App_GlobalResources\\\\";
_dirInfo = new DirectoryInfo(_dir2);
foreach (FileInfo _file in _dirInfo.GetFiles("*en-us.resx")) {
_file.CopyTo(_dir2 + _file.Name.Replace("en-us", idioma_.Cultura));
}
Thank you very much.
Creating or editing Resource files is not possible the same way as reading data.
In order to create or edit a resource file, you should do it the same way you create or edit XML files because resource files have with a specific structured XML elements.
Maybe this article will help you...
Dear Expert i am getting an error while saving an image the code is as follows
ClsImageManager objImgManager = new ClsImageManager();
Bitmap ImageBitmap = objImgManager.GetBitmapFromBytes(ImageData);
Response.ContentType = "image/tiff";
ImageBitmap.Save(Response.OutputStream, ImageFormat.Tiff);
ImageBitmap.Dispose();
Response.End();
when i used Image.format.jpeg the code is working good but when i changes it to ImageFormat.Tiff then i am getting an error a generic error occurred in gdi+.
You should note that GDI/GDI+ (System.Drawing namespace) is not officially supported in ASP.NET - see "Caution" in http://msdn.microsoft.com/en-us/library/system.drawing.aspx.
WIC is supposed to be used instead GDI+ (see http://weblogs.asp.net/bleroy/archive/2009/12/10/resizing-images-from-the-server-using-wpf-wic-instead-of-gdi.aspx)
Said that, many had successfully use GDI+ in ASP.NET. Most probably, you should attempt saving image into memory stream (or on file) and then writing saved image into the response. See this link for details: http://www.west-wind.com/weblog/posts/2006/Oct/19/Common-Problems-with-rendering-Bitmaps-into-ASPNET-OutputStream
Another work-around can be related to user account. Apparently, GDI/GDI+ is bound to device context (screen, printer etc) and they may not be available under service accounts. So you may try running your ASP.NET code on some normal user account if that helps or not.
You may need to try explicitly encoding the image save.
Have a look at the code example at the bottom of this MSDN documentation on Image.Save
Image.Save Method (String, ImageCodecInfo, EncoderParameters)
The same actions can be applied to your save.
However, it could also possibly be that your objImgManager is disposing of the buffer where the image is stored before you can save it.
Bitmap ImageBitmap = objImgManager.GetBitmapFromBytes(ImageData);
You can get around this by creating a copy of the image by doing this:
Bitmap ImageBitmap = new Bitmap(objImgManager.GetBitmapFromBytes(ImageData));
I have a Flex application with multiple modules.
When I redeploy the application I was finding that modules (which are deployed as separate swf files) were being cached in the browser and the new versions weren't being loaded.
So i tried the age old trick of adding ?version=xxx to all the modules when they are loaded. The value xxx is a global parameter which is actually stored in the host html page:
var moduleSection:ModuleLoaderSection;
moduleSection = new ModuleLoaderSection();
moduleSection.visible = false;
moduleSection.moduleName = moduleName + "?version=" + MySite.masterVersion;
In addition I needed to add ?version=xxx to the main .swf that was being loaded. Since this is done by HTML I had to do this by modifying my AC_OETags.js file as below :
function AC_FL_RunContent(){
var ret =
AC_GetArgs
( arguments, ".swf?mv=" + getMasterVersion(), "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
, "application/x-shockwave-flash"
);
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
This is all fine and works great. I just have a hard time believing that Adobe doesn't already have a way to handle this. Given that Flex is being targeted to design modular applications for business I find it especially surprising.
What do other people do? I need to make sure my application reloads correctly even if someone has once per session selected for their 'browser cache checking policy'.
I had a similar problem, and ended up putting the SWF files in a sub-directory named as the build number. This meant that the URL to the SWF files pointed to a different location each time.
Ideally this should be catered for by the platform, but no joy there. But this works perfectly for us, and integrates very easily into our automated builds with Hudson - no complaints so far.
Flex says:
http://www.adobe.com/livedocs/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001388.html
What I have done is checksum the SWF file and then add that to its url. Stays the same until the file is rebuilt/redeployed. Handled automagically by a few lines of server-side PHP script
here is sample.
function AC_FL_RunContent(){
var ret = AC_GetArgs(arguments, ".swf?ts=" + getTS(), "movie",
"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
"application/x-shockwave-flash");
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function getTS() {
var ts = new Date().getTime();
return ts;
}
AC_OETags.js is file and it exists html-template several places.
but as my posting said, I am facing another type of problem.
The caching is not done by Flash Player but by the browser, so it's out of Adobe's control. I think you have found a workable solution. If I want to avoid caching I usually append a random number on the URL.