I'm writing UWP app (C# and C++/CX).
My app gives user an opportunity to save video recorded by some connected camera.
I use OpenCV VideoWriter for it because I have to add video effects to C# SoftwareBitmap (comes to me from MediaFrameReader).
Thats how I'm creating VideoWriter in C++/CX code:
videoWriter.open(
pathToCreatedFile, // Works with "videos", but not with "desktop" or other
encodingProperties.codec,
encodingProperties.fps,
cv::Size{ (int)frameSize.Width, (int)frameSize.Height }
);
If I pick default Windows "Videos" library for saving, everything is good, but when I try to use "Desktop" folder for example or any other specific location, my output .mp4 file is 0KB.
Is it possible to save file in random directory in UWP and how can I reach it?
P.S. My minimal version is November update.
By design, you don't have access to arbitrary file folders from a UWP. You can request specific media libraries via a declared capability easily: documentsLibrary, documentsLibrary, picturesLibrary, and/or picturesLibrary.
There is no option for accessing the desktop directly.
The broadFileSystemAccess capability would allow this, but this is a restricted capability which means it will be difficult to publish it to the Windows Store (if that's your plan).
See Microsoft Docs.
Related
Our application writes logs to a file at a folder called UnityEngine.Application.persistentDataPath.
Now on Android we can open the file browser and open the log file. Not so on iOS. Short of Jailbreaking the phone to access all folders
Is there a way to access log file in that folder on iOS?
If not, is there another place where I can create that log file, so that the same is accessible e.g. from the file apps? Would Environment.SpecialFolder.MyDocuments work?
Note I am trying to write the file from C# code within unity environment, and ideally would NOT want to jump into NSLog to do this. Just a plain vanilla FileHelper.AppendAllText(LOG_FILE_NAME, "message"); I seek your help in finding a good value for that LOG_FILE_NAME.
Alternatively, rather than us trying to write the logs in a file, is there something better out there in Unity that works cross platform? Something like an inbuilt log file writer sink?
iOS: Application.persistentDataPath points to /var/mobile/Containers/Data/Application//Documents
You can access the ios containers with xcode.
Open xcode, install the app on the device, then open "Window"->"Devices". You can now click on the gear wheel -> "Download Container.."
Niklas has provided you the answer to #1 which is how to access the file on your iOS device.
If you want to make your files accessible to other apps you should check out the UIFaileSharingEnabled functionality for your app.
https://developer.apple.com/documentation/bundleresources/information_property_list/uifilesharingenabled
I am going to create an c# windows application for transfering image file from an android phone to my Wondows PC - when I connect phone with my PC(using data cable). When I given the path "Computer/Nuxes5/..." in C# for accessing files from mobile, (Got from the windows Explorer address bar). Then getting incorrect path. Following is the code I have given for accessing files.
Directory.GetFiles(#"Computer/Nuxes5/...");
Can any one please suggest me, how to access the mobile files using C#.
You need to use MTP file transfer. Since you are using Windows, the best thing to do is to use COM with the Windows PortableDeviceApiLib library. This is not an easy task. The WPD API link in one of the comments above is a good reference.
You should also install Microsoft MTP Simulator 3.0 and look at the sample code that comes with it.
In MTP, every file or folder stored on the device is an object with a handle. To retrieve a file or a folder, you have to retrieve the object handle, then check to see if it is a file or a folder by checking its objectFormatCode property. Folders have the object format code set to 0x3001. You can get the entire list from the MTP Spec.
Once you have the WPD/PTP wrapper set up, you can start sending MTP commands to the device. For getting files from the device, the procedure is the following.
Get the available storage ids by calling getStorageIds();
For the storage id you are interested in (internal storage/SD card), call getObjectHandles() to get a list of all files/folders.
Loop through the root folder handle to look for the file you are interested in. For each handle you get, call getObjectInfo() to get the details about that handle.
Once you have a handle whose name and format code matches what you are looking for, call the getObject() function to download the file.
Also remember that you cannot download all the contents at the same time. You have to call getObject() for each file handle you need to download.
I'm very new to Visual Studio 2010. I decided to create a simple WFA with C#.
Everything work fine with Images and Audio playback. My intention is to create a standalone application and send it to my friend as a gift. Problem I facing now is that when I tried to publish the application, the Images / Audio is still using the same location in my PC. So it won't play nor display any images.
Any comment on this or guide for me? I did try search for solution but doesn't seems to have any luck.
This is the code that I used to play Audio :
SoundPlayer ply = new SoundPlayer(#"C:\Users\Liam619\Documents\Visual Studio 2010\Projects\BirthdayApp\BirthdayApp\Resources\BirthdaySong.wav");
If I remove or change the path, the Application will hit error for locating the Audio file.
There may be several solutions to your problem.
a) embed the sound into a resource. As a beginner, resources may be a bit tricky to get it right the first time. But I want to encourage you reading something about it. You'll need resources when you want to translate your first program.
b) create an installer which copies the sound file to the installation directory. Try InnoSetup. If you're a programmer, sooner or later, you'll need to create a Setup anyway. Always worth knowing how to do that.
In that case, you still need the path to the sound file, but if you install your EXE into the same path as the sound file, see getting the application's executable directory.
everything in the database whether images or audio refers to your own server database.you have to send the database too with the app and the correct version .NET framework needs to be installed on the target PC.
Pretty much I must find a way to populate image boxes with the corresponding information to the images, if it's possible in a Windows 8/Metro/Store App. I have a database with all the physical paths of the images which are stored on the local computer e.g: "c:\BookImages\spud.jpg". Now when i pull the information from the database with information about the book, I also take the file path of image("c:\BookImages\spud.jpg"). All i need to now do is to fetch the image and display it in a image box. But i do not how to do this, i have been researching for a while now, and I'm coming to the understanding that i cannot select file's from other than the actual install directory of the windows app. Unless i use a FileOpenPicker, which will be a useless for the user to select the folder which contains the images every time they run the app. If anyone has a solution to my problem please let me know it will be much appreciated.
See If all the directories were given access for a win rt app then it would be a security risk
So some specific folder are available try storing user data in there . After that only File Picker can Help.
Heres the link
Folders for winrt
Its a Microsoft policy so Please design app accordingly. You might needd to set capabilities in the app manifest file for some folders. Please go through it :)
The short answer is to have the user pick the folder once and save the StorageFolder in the Windows.Storage.AccessCache.
The long answer is that all this boils down to having your data store in a place that is programmatically accessible.
One option, as Anobik pointed out, is to use either your appdata folders (where you have open access), or something like the Pictures Library, which you can access given a capability in the manifest. This way you don't need to ask the user.
If you use the file picker to let the user select a folder for the data store, he or she has granted permission to access that folder programmatically, including its contained files.
The important thing is that you have to preserve that permission across sessions, which is the purpose of the AccessCache.
Think of a StorageFolder object (and a StorageFile) as an abstraction for a pathname--you never really want to save pathname strings unless you have inherent programmatic access to that location. This isn't true for stuff from the file picker, so you have to use the AccessCache to essentially save the folder reference and its permissions.
Kraig Brockschmidt
Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press (also see second edition preview)
I am working on a Metro app that shows the content of a given folder in a ListView control.
MS decided that developers don't need the System.IO.Directory class and removed it entirely from the framework.
I am looking for a replacement to enumerate files in C# in a metro style app. I have checked all the enumeration samples provided by MS and they all seem to only enumerate the Windows Libraries using the KnownFolders class, something like:
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
and calling the GetFilesAsync() or GetFoldersAsync() methods depending on your needs. These are all gold if I wanted to enumerate only inside the pictures or music library. However I am looking to enumerate files on directories that are not included in a library.
Anyone knows how this is possible in WinRT???
You are, by design, extremely limited in this area for Metro apps. The idea is that a Metro app is only given access to those things that it is trusted to access, so you can either:
access local storage, specific to your application
access a handful of well-known storage locations, or
access a specifically granted location.
Take a look at http://msdn.microsoft.com/en-us/library/windows/apps/hh464959.aspx to get an idea as to what you'll be able to access.
From http://tirania.org/blog/archive/2011/Sep-15.html :
When you use C# and VB, you are using the full .NET framework. But
they have chosen to expose a smaller subset of the API to developers
to push the new vision for Windows 8.
And this new vision includes safety/sandboxed systems and asynchronous
programming. This is why you do not get direct file system access or
socket access and why synchronous APIs that you were used to consuming
are not exposed.
Now, you notice that I said "exposed" and not "gone".
What they did was that they only exposed to the compiler a set of APIs
when you target the Metro profile. So your application will not
accidentally call File.Create for example. At runtime though, the CLR
will load the full class library, the very one that contains
File.Create, so internally, the CLR could call something like
File.Create, it is just you that will have no access to it.
This split is similar to what has been done in the past with
Silverlight, where not every API was exposed, and where mscorlib was
given rights that your application did not have to ensure the system
safety.
You might be thinking that you can use some trick (referencing the GAC
library instead of the compiler reference or using reflection to get
to private APIs, or P/Invoking into Win32). But all of those uses will
be caught by AppStore review application and you wont be able to
publish your app through Microsoft's store.
You can still do whatever ugly hack you please on your system. It just
wont be possible to publish that through the AppStore.
So there's probably no official way, and if there's an unofficial way, it probably won't be accepted to the app store.
Just in general this makes sense: I don't want to download a seemingly legit application just to have it scan my hard drive and find my "budget.xls" spreadsheet which includes my banking/credit information.
EDIT: it is possible to grant temporary access to secure files/folders through WinRT's file picker, but it has to be invoked and chosen explicitly by the user.
You can use the StorageFolder.GetFolderFromPathAsync Method to get a StorageFolder instance from a path.
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(#"C:\...");
Note that you may not have permission to do this for all paths on your machine though.
Similar situation. Wanted to access chrome bookmarks file to parse. Had to use FileOpenPicker initially, but the file that it returns can be "cached" in the futureaccesslist(?) for subsequent retrieval.