I have two csv files. I need to parse one of the files based on language selected on device. I have put those in Resources folder and created two folders using qualifiers(en-US, da-DK). Inside these two folders, i have put two files with same name(e.g. answers.csv). When i run application, it says that it could not find the file.
i used following code to convert the file into StreamReader
StorageFolder installationFolder = Util.CommonUtils.getAppLocation();
StorageFile file = await installationFolder.GetFileAsync(path);
Stream stream = await file.OpenStreamForReadAsync();
StreamReader reader = new StreamReader(path);
What am i missing here?
Related
I uploaded a word document on Google Drive. I am downloading the file in HTML format in following two ways.
First method: I open the file in Google Docs and then downloaded the file: File -> Download as -> Web page (.html, zipped). I unzip the tar and then I get the HTML file. Its size is 62 kB.
Second method: I used Drive API v3 to create (or upload) the word document to Google Drive. Then I exported the file to HTML format. Its size is 173 kB.
My question is why there is difference of almost three times in size of HTML file? What should be done to get the same file size (62 kB) when downloading (or exporting) using Drive API?
This is the Drive API code I am using to create and export the file.
Drive service = getDriveService();
File fileMetadata = new File();
fileMetadata.setName("Test Document");
fileMetadata.setMimeType("application/vnd.google-apps.document");
FileContent fileContent = new FileContent("application/vnd.openxmlformats-officedocument.wordprocessingml.document", new java.io.File("/home/test/test.doc"));
File createResponse = service.files().create(fileMetadata, fileContent).execute();
java.io.File parentDir = new java.io.File("/home/test/");
if (!parentDir.exists()) {
throw new IOException("Parent directory does not exists.");
}
OutputStream out = new FileOutputStream(new java.io.File(parentDir, "Test Document"));
service.files().export(createResponse.getId(), "text/html").executeAndDownloadTo(out);
Kindly help me with this issue.
Thanks.
I need to open a pdf document file from the asset folder from windows phone 8 app. First I need to check whether any pdf reader is available or not and if available, the pdf document should be opened from the asset folder.
There are two ways of using a file. You can mark it as
Resource Files: Data files that are compiled into either an executable or library assembly. To access a resource,
Example :
Stream jsStream = Application.GetResourceStream(new Uri("folder\\e_data.pdf",UriKind.Relative)).Stream;
Content Files: Standalone data files that have an explicit association with an executable assembly.
To access content file, use
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync();
EXAMPLE
Mark the pdf file as content in properties -> build action.
async void openPDF()
{
Uri filePath = new Uri(#"ms-appx:///example.pdf");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(filePath);
//For opening that file,
if (file != null)
await Launcher.LaunchFileAsync(file);
}
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.
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();
In a very simple first AIR application (I'm using Flash Builder 4.5), I am trying to accomplish the following on my MacBook:
Read a local file (JSON format) into the AIR app.
Parse through the file.
Display some selected contents in a grid.
That's it.
I've found an example that does some simple JSON parsing in Flex, but the problem is that it loads the JSON source from a remote web site.
So do I need to load any file-specific libraries to make this work in AIR? Or can I simply refer to the file by using the Mac file-path? I just want the local file to be the JSON source. The parsing is already taken care of.
You can use FileStream like:
var myFile:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var myFileStream:FileStream = new FileStream();
myFileStream.open(myFile, FileMode.READ);
var yourJSONdata:String = myFileStream.readUTFBytes(myFileStream.bytesAvailable);
myFileStream.close();
Initializing a FileStream object, and opening and closing files