write and read html file from webview windows 8 store app - windows-store-apps

I have a requirement to produce reports in html (So they can be styles via css etc...) The application is a Windows 8 Store App.
I have created a template and am able to produce the html file. I initially saved it here
Windows.ApplicationModel.Package.Current.InstalledLocation
Great right? wrong! The WebView control will not read from that location!
I also tried writing to the Assets folder of my app. Nope! Permission Denied.
Windows 8 store apps have limited rights to the folder system.
Question:
Where can I put dynamically generated html files (run time) so that they can be read by the WebView Control?
Thanks for any feedback.

In case anyone else has had this problem, or like me you are new to windows store development. Here is the answer (Got help from pluralsight)
Code:
StorageFile file = await destFolder.GetFileAsync(fileName);
string url = "ms-appdata:///local/Estimates/" + fileName;

Related

Downloading and replacing file in package

In my Visual Studio 2013 Solution, I added a folder "mAppData" with some static Content for the app.
One of the files is a Textfile ("imprint.txt").
On a phone page, I Display the content of this file. This works fine.
Is there a way to replace this file on runtime? I want to download new Content from web and replace this file with the downloaded content.
rather than downloading and replacing the "imprint.txt" you could simply download the imprint as text (from your imprint.txt - stored online) and display it:
var client = new System.Net.WebClient();
client.DownloadStringCompleted += (sender, args) => MessageBox.Show("downloaded imporint: " + args.Result);
client.DownloadStringAsync(new Uri("http://yourSite.ch/imprint.txt"));
My sample simply shows a MessageBox with the downloaded text. However, you can update a text control or similar.
If you want the content to be available even if you are temporary offline, you can store the file in the filestorage.
Consider adding multiple files for different languages in your build and load the file depending on the localization of your phone.
However - replacing a existing file for your Solution is not allowed on runtime. Consider this as a safety feature. If the Codebase of your app could change during runtime, your code would be injectable by an attacker.
You can't alter the package content at runtime, it is read-only.
The place where you can store data locally is the Isolated Storage. What you should do is create a file in the Isolated Storage at first launch that stores the original content of your file ("imprint.txt") and then you'll be able to change it any time you want.
Here is a tutorial that explains how to read and write text in the Isolated Storage: All about WP7 Isolated Storage - Read and Save Text files

Windowsphone - How to Make App can open Some Fileformats

i have a question
i want to know how can i open downloaded file in my app (like when you download .PDF File in Internet Explorer it shows apps that can open .PDF files )
please help me snippet of codes !
first you have to save your file in isolated storage and you need to use launcher this code would help you:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Access the bug query file.
StorageFile yourfile = await local.GetFileAsync("Pradeep.pdf");
// Launch the bug query file.
Windows.System.Launcher.LaunchFileAsync(yourfile);
}
this launcher is available in windows phone 8 only.
As stated in MSDN :
"You can use file and URI associations in Windows Phone 8 to automatically launch your app when another app launches a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app."
Basically you need to do following steps :
Register your application to be associated to a specific file type, for example .pdf file extension in this case. This step done by adding <Extension> in WMAppManifest.xml.
When your application get launched upon user opening a .pdf file, get file id from query string then get the physical file using SharedStorageAccessManager based on file id.
The rest is to handle opening the file in your application.
I found this very nice blog explaining the detail of every steps, accompanied with downloadable source code.
PART I: explaining background concept and creating application to launch associated file
PART II: explaining details of step 1-3 above with sample application

Opening html file from IsolatedStorage in a WebBrowser componenet in Windows Phone

I have stored an HTML file in IsolatedStorage as test.html.
In UI I have a WebBrowser component called browser. I'm using the following code to show the webpage in the browser:
browser.Navigate(new Uri("isostore:/test.html", UriKind.Absolute));
However it's giving me the prompt to search for an app in store, as if I'm trying to use LaunchUriAsync or LaunchFileAsync API.
I guess the problem is with the Uri format. What should be the correct Uri format in this case?
I have solved it, by removing 'isostore:/' prefix from the Uri string. I know that without any prefix the file path would refer to the application folder, not the isolated storage. It seems they've made an exception for the WebBrowser component.
This is what works now:
browser.Navigate(new Uri("test.html", UriKind.Relative));
C:/Data/Users/DefApps/AppData/{43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}/Local/test.html
The path above is an alternative and absolute path to the isolated storage. This string, {43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}, is unique to the app but can be set/found from within the properties folder of your visual studio project. You can also obtain it by using the following lines in the C# code:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
String mystring = localFolder.Path;

Can I use asp FileUpload to select a folder?

I need something like the FileUpload control in asp.net that will allow the user to browse for a folder and enter a file name of a new file to upload.
From what I've seen FileUpload requires a file to be selected. It seems that html input type="file" has the same requirement.
Thanks!
Selecting an entire folder is not possible in FileUploadControl as it is meant for a single file. Although you can have a Multi File Selection. Multiple File Upload User Control
C# has build-in FTPrequest class where you can create folders, upload files, delete files etc.
If you want to upload folders from a webpage, you cannot use this technology in the browser, then you will have to use a rich-client such as Java, Flash or similar plugin.
If you can provide the users with a Windows or Mac client, you can use C# (either .NET or Mono) for the FTP transfer.
ZIP files arent a problem for ASP.net nor C#, but you still only upload 1 file (zip-archive) and then its up to the server to unzip it using eg. C#. Look at 7-Zip which is opensource, then you might get some ideas too.
You could also just try and use the build-in lib for it (compression):
http://www.eggheadcafe.com/community/csharp/2/10050636/how-to-compress-and-decompress-file-in-c.aspx
or try this link...
http://www.aurigma.com/docs/iu7/uploading-folders-in-aspnet.htm

Accessing files from Windows Store App

I'm working in Windows 8 Operating System building Windows Store apps.
I'm trying to access one XML file(present within the solution) via the code below.
var file = System.Xml.Linq.XDocument.Load(#"E:\Gowtham\Data.xml");
But I'm getting "Access to the path 'E:\Gowtham\Data.xml' is denied.'" exception.
I tried all possible ways to remove the read-only attribute of the folder and the file but no use.
I used command prompt to change the attributes of the file, also I tried manually but the read-only attribute of that folder is not changed.
Kind help pls.
You can't get ANY file like that way. I highly recommend you to read these links. You can access files from library if you have declared library access capability.
File system places accessible through WinRT API
Windows 8: The right way to Read & Write Files in WinRT