c:\users\public folder not accessible from metro apps on x86 machines - windows-store-apps

I am not able to access C:\Users\Public\Documents folder from Windows store app running on a x86 machine using StorageFolder.GetFolderFromPathAsync("C:\Users\Public\Documents"). It works fine on my win8 desktop. any idea why I get this error?
Thanks,
MetroUI.

You can't access the file system outside your apps sandbox using that method. That will only access files in your apps isolated storage.
If you want to get files from outside the sandbox you will have to use a FileOpenPicker and have the user select the file
var picker = new FileOpenPicker();
picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
var file = await picker.PickSingleFileAsync();
if (file != null)
{
IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
}
Then you would work with the data in the stream.

J.B is right, you can't access that folder directly due to sandbox limitations, but there are 2 other approaches you can take that might suite you better.
If you Add Documents Library to your app's Capabilities, you will be able to access the files in user's Documents library directly (it should include Public Documents as well, unless the user changed his settings), as long as you have declared a File Type Association for that extension to your app's Declarations. You can set both by editing Package.appxmanifest. Use the following code to access the StorageFolder:
var folder = KnownFolders.DocumentsLibrary;
Keep in mind that you need a company account to publish apps with Documents Library capability to Windows Store.
Alternatively you can use FolderPicker so that the user will grant you access to that folder. In this case you don't need any capabilities or declarations and you will be able to access all files:
var picker = new FolderPicker();
picker.FileTypeFilter.Add(".txt");
var folder = await picker.PickSingleFolderAsync();
You don't need the user to select the folder every time the app starts. You can store its reference to FutureAccessList to access it later and store the corresponding token (e.g. to settings):
var token = StorageApplicationPermissions.FutureAccessList.Add(folder);
When you want to access the folder again just use the token to get the folder reference:
folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(token);
var items = await folder.GetItemsAsync();

Related

Is there a way to use Google App Script to create a Drive file sharable in view-only but that can't be re-shared or downloaded?

I have just recently starting coding and using AppScrpits, and I have set up an app that among other things creates PDF files in a Drive folder and stores the view links in a Sheet.
These files should be accesible only by people with the same domain in view only, non-sharable and non-downloadable.
I set the access and permission as intenden and everything works fine, but the PDF files are still downloadable and sharable by the viewers. Normally I would set this option by right cliking the file and setting the configuration manually, but since I have to process a large number of files I wonder if there is anyway to do this with appscripts.
With the code below access and view permission works as intended, but I can't find any referance to set aditional configuration so that the file is non-downloable or sharable.
let pdf = DriveApp.getFileById(nuevo.getId())
.getBlob()
.getAs('application/pdf');
pdf.setName('placeholder'.pdf');
let file = ubicacion.createFile(pdf);
file.setSharing(DriveApp.Access.DOMAIN_WITH_LINK, DriveApp.Permission.VIEW);
var ultimaFila = sheet.getLastRow() +1;
sheet.getRange('Hoja 1!B' + ultimaFila).setValue(file.getUrl());
Thanks!!!

use local JSON file with react and electron

so I have created an electron App with the help of react.js.
The app should mainly display charts, for which I use chart.js. The data of the chart files need to be updated monthly, since I get new data every month from another department per Excel, which I quickly export to a JSON. Obviously I don't want to create a new production electron app every month. So is it possible to retrieve data from json files after production? I can't find anything on the web unfortunately.
How do I go about that, since I can't access JSON files outside of my src folder with react or can I?
thanks in advance!!
Electron is for creating desktop apps so you have full access to the file system.
To read a local file you can install and use Node fs. fs supports Promises, callbacks and synchronous methods.
Rather than hardcode the filepath, you probably want to do some friendly UI stuff like on first launch, ask the user to select the file they want to load and then store that path as a preference. Then on subsequent launches, test if the file exists and load it, otherwise alert the user to pick another file, etc.
let thePath = "/Users/Spring/Desktop/ticket.txt"
var fs = require('fs');
fs.readFile(thePath, 'utf8', function (err, data) {
if (err) return console.log(err);
// data is the contents of the text file we just read
});

How can I run a command in windows store app?

I need to run a command from windows store app?
the command is something like this : java -jar abc.jar
How can I do that?
EDIT :
I tried this but with no luck. It says file not found.
string exeFile = #"C:\DATA\start.bat";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
The app container blocks this behavior for Store apps.
First of all, you're attempting to obtain a StorageFile through your package InstalledLocation folder, which will not work. InstalledLocation is a StorageFolder, and its GetFileAsync looks for files only within that immediate folder. This is why it's returning file not found.
The API that takes an arbitrary path is Windows.Storage.StorageFolder.GetFileFromPathAsync. However, your ability to access files is limited by the app container. You can access files in your package folder or app data locations by default, or the various media libraries if you've declared access in the manifest, but otherwise you have to go through the file picker so the user is aware of what you're doing and can grant consent. Simply said, this is the only way you'll get to a file in a location like c:\data. You can play with this using Scenario 1 of the Association launching sample and the "Pick and Launch" button.
If you can get that access permission, then in you'll be able to launch a file if it's not a blocked file type. Data files (like a .docx) that are associated with another app work just fine, but executables are wholly blocked for what should be obvious security reasons. You can try it with the sample I linked to above--pick .bat, .cmd, .exe, .msi, etc. and you'll see that LaunchFileAsync fails.
Also note that the other launcher function, LaunchUriAsync, also blocks file:/// for the same reasons.

Access asset / resource file in an ActionScript Library project

I'm using an ActionScript Library project to share code and assets / resources between a Mobile and a Desktop ActionScript projects.
The library project has been added to the two other projects via the 'Add Project' option on the 'Library Path' tab, with the linkage type 'Merged into Code', and all the classes within it can be accessed by the other projects, and work properly.
However it contains a SQLite database file, which I want to copy out to the File.applicationStorageDirectory on the target system on the first load of the app, and I'm not sure how to get a reference to the file within the library project to copy it out.
The location of the db file is: LibraryProj - src/database/dbFile.db and I thought using File.applicationDirectory and then a path 'into' the swf would give me access to it, but none of the following tests say the file exists.
var test:File;
test = File.applicationDirectory.resolvePath("app:/src/database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("src/database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("dbFileDb.db");
trace("test.exists==" + test.exists);
Is this the correct method to copy resource / asset files out of a swf containing merged libraries and onto the app's storage directory? Is it even possible to share resources / assets from Library projects in this way?
Any advice would be very much appreciated.
After doing some more research about using the [Embed] tag in AS3, I've now worked out that this is what I should have been using to make the file available to consuming projects (I'd previously only used it for images, and didn't think of it for other file types too).
[Embed('igniteDb.db', mimeType="application/octet-stream")]
public static const myReferenceDbFile:Class;
To copy the file to the File.applicationStorageDirectory i'm using the following code. It converts the embedded file to a byte array, and then writes this out via a FileStream class to the destination file.
//write the embedded database file data into app user files directory
var bundleDbBytes:ByteArray;
bundleDbBytes = new myReferenceDbFile();//gets a reference to the embedded db file
var outputDbFile:File = File.applicationStorageDirectory.resolvePath(DB_FILE_NAME);
var fileStream:FileStream = new FileStream();
fileStream.open(outputDbFile, FileMode.UPDATE);
fileStream.writeBytes(bundleDbBytes);
fileStream.close();
And hey presto, the database is ready to use.

List the contents of a local folder from within swf

I have succesfully read a file from the local computer in as3, I would like to know if it is possible to list the contents of a folder in some way. The swf will run from browser and acces local files only. No server, no outside world contact.
this is how I have accesed and displayed the local file.
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, useData);
loader.load(new URLRequest("abc.txt"));
function useData(event:Event):void {
var data:String = event.target.data.toString();
myTextField.text = data;
}
You can present the user with a standard OS window to open a file they can select themselves from their filesystem.
from the manual: FileReference.browse:
Displays a file-browsing dialog box that lets the user select a file to upload. The dialog box is native to the user's operating system. The user can select a file on the local computer or from other systems, for example, through a UNC path on Windows.
So even though you cannot list the files in a directory yourself, you can prompt the user to select a file for you.