Where can i find folder with installed modern ui apps? Im developing some app which uses .txt files to store information (win8 doesnot support datebase on arm - facepalm) but they seem to not work properly - thats why i want to access them.
Thanks!
That is not the correct way of doing things in Metro. I assume you mean db files, or txt files. Simply access the local text file from the project folder.
Here is a great tutorial on how you would go about doing so: http://www.codeproject.com/Articles/432876/Windows-8-The-Right-Way-to-Read-Write-Files-in-Win
An example:
private async void ProjectFile()
{
// settings
var _Path = #"Metro.Helpers.Tests\MyFolder\MyFolder.txt";
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// acquire file
var _File = await _Folder.GetFileAsync(_Path);
Assert.IsNotNull(_File, "Acquire file");
// read content
var _ReadThis = await Windows.Storage.FileIO.ReadTextAsync(_File);
Assert.AreEqual("Hello world!", _ReadThis, "Contents correct");
}
Related
I have an application where I need to show the .pptx and .pdf files. For pdf files I am using react-native-pdf and file is opening fine in my App but when it comes to .pptx files we have 2 libraries:
1. https://www.npmjs.com/package/react-native-doc-viewer
2. https://www.npmjs.com/package/react-native-file-viewer
react-native-doc-viewer is not being actively maintained and a lot of issues :(
But both of them were giving a prompt to select an app like Wps Office or Microsoft apps but they were not opening as Pdf files opened in my app. Whats the reason behind this? We cannot open pptx file in our app?
I read the react-native-doc-viewer android native code. it is actually is to download a doc not to view it. the following is the code:
#ReactMethod
public void openDoc(ReadableArray args, Callback callback) {
final ReadableMap arg_object = args.getMap(0);
try {
if (arg_object.getString("url") != null && arg_object.getString("fileName") != null) {
// parameter parsing
final String url = arg_object.getString("url");
final String fileName =arg_object.getString("fileName");
final String fileType =arg_object.getString("fileType");
final Boolean cache =arg_object.getBoolean("cache");
final byte[] bytesData = new byte[0];
// Begin the Download Task
new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute();
}else{
callback.invoke(false);
}
} catch (Exception e) {
callback.invoke(e.getMessage());
}
}
it uses FileDownloaderAsyncTask to download files. if you are familiar with it.
if you want to show excels, Docx, you can use the google doc line convert it to Html, then in the webView to show it. the format like it: https://docs.google.com/gview?embedded=true&url=[doc address], the same effect as ios.
In my cn1 application, I want to make it possible for the user to back up their own cloud storage. For example, your own Dropbox account.
I was looking for a solution on the WEB. I think what I found (dropbox-codenameone-sdk) I can only manage a known account because I need to know consumerSecret and consumerKey. When I write the code, I don't know the actual user account information.
Based on the operation of other applications, I assume I have to log in to the actual user his account (eg Dropbox).
Please help what API calls can I do this.
Use the Share API in Display. You can zip the data using the zip cn1lib and save it in a file within the file system then use the share API to let the user pick a native app to share it with. On the simulator it will have options such as email/facebook but on the device you should have more options.
I think I'm using the API properly. Although I did not set correctly the file access on my phone.
However, the error occured in the simulator.
The mail and DropBox sharing on my android phone is successful.
I don't like the file getting a prefix (IMG_20200112_204126_). Can I change this?
I include screenshots and a code snippet.
Best regards, Péter
public ShareForm(Resources resourceObjectInstance, Form parentForm) {
this.parentForm = parentForm;
this.theme = resourceObjectInstance;
Layout layout = new BoxLayout(BoxLayout.Y_AXIS);
setLayout(layout);
getToolbar().setBackCommand("", e -> {
this.parentForm.showBack();
});
/* file exist on simulator */
/* String filePath = FileSystemStorage.getInstance().getAppHomePath() + "temp/vendeg_201807011754.json"; */
/* file exist on phone */
String filePath = "file:///storage/emulated/0/Download/stratos.pdf";
String mimeType = "application/octet-stream";
boolean exist = FileSystemStorage.getInstance().exists(filePath);
long size = FileSystemStorage.getInstance().getLength(filePath);
SpanLabel spanLabel0 = new SpanLabel("File path: " + filePath);
SpanLabel spanLabel1 = new SpanLabel("File exist: " + exist);
SpanLabel spanLabel2 = new SpanLabel("File size: " + size);
ShareButton shareButton = new ShareButton();
shareButton.setText("Share data (ShareButton)");
shareButton.addActionListener(e-> {
shareButton.setImageToShare(filePath, mimeType);
shareButton.actionPerformed(e);
});
Button shareButton1 = new Button("Share data (Share API in Display)");
FontImage.setMaterialIcon(shareButton1, FontImage.MATERIAL_SHARE);
shareButton1.addActionListener(e -> {
Display.getInstance().share(null, filePath, mimeType, shareButton1.getBounds(new Rectangle()));
});
addComponent(spanLabel0);
addComponent(spanLabel1);
addComponent(spanLabel2);
addComponent(shareButton);
addComponent(shareButton1);
}
I am trying to use this pluggin (express-zip). At the Azure Storage size we have getBlobToStream which give us the file into a specific Stream. What i do now is getting image from blob and saving it inside the server, and then res.zip it. Is somehow possible to create writeStream which will write inside readStream?
Edit: The question has been edited to ask about doing this in express from Node.js. I'm leaving the original answer below in case anyone was interested in a C# solution.
For Node, You could use a strategy similar to what express-zip uses, but instead of passing a file read stream in this line, pass in a blob read stream obtained using createReadStream.
Solution using C#:
If you don't mind caching everything locally while you build the zip, the way you are doing it is fine. You can use a tool such as AzCopy to rapidly download an entire container from storage.
To avoid caching locally, you could use the ZipArchive class, such as the following C# code:
internal static void ArchiveBlobs(CloudBlockBlob destinationBlob, IEnumerable<CloudBlob> sourceBlobs)
{
using (Stream blobWriteStream = destinationBlob.OpenWrite())
{
using (ZipArchive archive = new ZipArchive(blobWriteStream, ZipArchiveMode.Create))
{
foreach (CloudBlob sourceBlob in sourceBlobs)
{
ZipArchiveEntry archiveEntry = archive.CreateEntry(sourceBlob.Name);
using (Stream archiveWriteStream = archiveEntry.Open())
{
sourceBlob.DownloadToStream(archiveWriteStream);
}
}
}
}
}
This creates a zip archive in Azure storage that contains multiple blobs without writing anything to disk locally.
I'm the author of express-zip. What you are trying to do should be possible. If you look under the covers, you'll see I am in fact adding streams into the zip:
https://github.com/thrackle/express-zip/blob/master/lib/express-zip.js#L55
So something like this should work for you (prior to me adding support for this in the interface of the package itself):
var zip = zipstream(exports.options);
zip.pipe(express.response || http.ServerResponse.prototype); // res is a writable stream
var addFile = function(file, cb) {
zip.entry(getBlobToStream(), { name: file.name }, cb);
};
async.forEachSeries(files, addFile, function(err) {
if (err) return cb(err);
zip.finalize(function(bytesZipped) {
cb(null, bytesZipped);
});
});
Apologize if I've made horrible errors above; I haven't been on this for a bit.
In the file picker Windows 8 sample a file is saved like this:
CachedFileManager.DeferUpdates(file);
await FileIO.WriteTextAsync(file, stringContent);
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
I'm serialising an object as XML so doing it slightly differently:
// CachedFileManager.DeferUpdates(file);
var ras = await file.OpenAsync(FileAccessMode.ReadWrite);
var outStream = ras.GetOutputStreamAt(0);
var serializer = new XMLSerializer();
serializer.Write(myObject, outStream);
// FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
It works with or without the CachedFileManager (commented out above).
So, should I include the CachedFileManager and if I do use it am I saving the file in the right way.
This code works and saves the file fine, but I don't like including code that I don't understand.
Yes, this code will work without CachedFileManager. But, when you use CachedFileManager, you inform the file provider that the file is in process of change. If your file is located on SkyDrive it is faster to create a file and upload it at once instead of update it multiple times.
You can have the full story there : http://www.jonathanantoine.com/2013/03/25/win8-the-cached-file-updater-contract-or-how-to-make-more-useful-the-file-save-picker-contract/
It simply tells the "repository" app to upload the file.
I'm simply trying to attach a file named Document.pdf in the DocumentsLibrary to an email using the Share Charm. My code below works perfectly on the Local Machine:
private async void OnDataRequestedFiles(DataTransferManager sender, DataRequestedEventArgs e)
{
List<IStorageItem> shares = new List<IStorageItem>();
StorageFile filetoShare = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync("Document.pdf");
if (filetoShare != null)
{
shares.Add(filetoShare);
filetoShare = null;
}
if (shares != null)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Title";
requestData.Properties.Description = "Description"; // The description is optional.
requestData.SetStorageItems(shares);
shares = null;
}
else
{
e.Request.FailWithDisplayText("File not Found.");
}
}
But when I run the exact same code on a Windows Surface Tablet, I get the dreaded "There's nothing to share right now." on the right in the Charms flyout area.
Here's a little more background to help:
I'm not looking to use a File Picker...I know the exact file I'm looking for
I've enabled the Documents Library Capability in the manifest
I've added a File Type Association for pdf in the manifest
and yes, the file does exist and is in the Documents Library
an email account is properly setup in the Mail App on the surface
I can successfully send text emails from the Tablet...just not emails with attachments
Like I said, this works on my Win 8 Development Machine as expected...just not on the Surface. I'm wondering if the Surface has different file or folder permissions?
Thanks for the help...this is driving me CRAZY
I finally figured it out - the problem was that my Event Handler was async (so that I could use await to set the StorageFile variable).
I solved it by setting the StorageFile variable earlier in my code so that it was already available when the Event Handler was called.
I still have no idea why it worked on my development machine, but no on the WinRT surface...
The handler can be an async method. In this case, it is critical to use DataTransferManager. Please refer to the MSDN page specifically for this scenario. For your convenience, the code from the page is copied to here:
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
}
private async void ShareStorageItemsHandler(DataTransferManager sender,
DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share StorageItems Example";
request.Data.Properties.Description = "Demonstrates how to share files.";
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
It is critical to place the following statement before any async method is called:
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
You only have half a second to get the whole job done (getting the file, attaching...etc.). If the half-second deadline occurs you'll get this "driving crazy" message. Consider implementing some resumable logic and replace the message with "the attachment is being prepared please try again in a few seconds" (or else).
Your WinRT device might be just slower than your development machine. The latter just does the job before the deadline...