How to load HTML file from another assembly to WPF WebBrowser Control - html

These are the projects in my solution:
HTMLApp (TypeScript) - contains index.html
WebBrowserApp (WPF) - contains main.xaml with WebBrowser control
I want to load the content of index.html into the web browser control inside main.xaml. Build Action of index.html is set as Resource.
I tried this code in the XAML but did not work:
myBrowser.Navigate(new Uri("pack://siteoforigin:,,,/HtmlApp/index.html"));

The WebBrowser control doesn't work with pack URIs.
The Source of the Uri that you pass to the Navigate method is supposed to be a URL or an absolute file path. The WebBrowser control doesn't support browsing resources or relative paths.
You could change the Build Action of index.html to Content, set the Copy to Output Directory property to Copy if newer and then navigate to the local file like this:
myBrowser.Source = new Uri(string.Format("file:///{0}/index.html", Directory.GetCurrentDirectory()));

Related

Why won't my images show in my HTML file?

Is there something wrong with my syntax? I have an images folder located in the same folder as the html file. Images from URLs work fine.
<img src="images/ai_1.png" width="500" height="300"/>
Images folder
Given that the directory is named templates…
You have some server-side (or build-time) code which takes a URL and somehow translates that into an instruction to generate an HTML document from that template and other stuff (probably includes and some page specific data).
The relative URL you have in the src attribute is computed from the URL of the generated HTML document.
The browser asks for that URL and the server can't find a suitable response for it.
The image files aren't templates so shouldn't be in the templates.
This kind of system typically has a specific directory to store static files in. The images should be in there.
You then need to specify a URL which is mapped onto that static directory by the server code.

CKEditor external image path

I"m having an option to insert image inside CKEditor. For that i saved the image file in physical path inside the Server(Wildfly 10) folder and adding an img tag by using editor instance with (instance.insertHTML) option. Its working fine when the image was inside the server folder. If the image was outside the server path its not rendering in the editor as well as in the browser.
Help to store the image in external path (outside the Server path) to render the image in CKEditor as well as in the browser.
I'm using primefaces extension for CKEditor.
Your web application only has access to certain areas of the file system served from under the webapp. This is fundamental webapp security so a user couldn't browse your server's file system for example.

Usage of audio and video tag in Nitrogen

Still working on my personal web server, I was trying to use the html5 audio and video tags within Nitrogen.
As there is no #audio nor #video records, I decided to insert html text directly in the page generated by nitrogen, the result looks like this:
<audio controls preload="metadata"><source src="../../My Music/subdir/song.ogg" type="audio/ogg" /source>audio tags not supported</audio>
In my understanding this should work because the audio tag is supposed to be interpreted directly by the client browser, and there is not any nitrogen id or event observer in the code.
But when I browse this code from Firefox, I briefly see the control opening, and then the audio element simply disappears.
If I copy paste the whole code generated by nitrogen (display html source page, copy and paste in a file located at the origin of the nitrogen project) and open it with the browser, it works fine. The relative path is correct, assuming that the search stats in nitrogen project. I have tried absolute path also, without success.
I don't know
if it builds a file name of the form ".._.._My music_subdir_song.ogg" like nitrogen does for url analysis,
or if it uses another directory to start the path,
or if it simply doesn't work the way I am thinking.
...
Edit: some complementary information:
I have done the following changes:
create one directory including some ogg files in the site/static directory + move a static test.html file in the site/static. If I open directly test.html -> ok. if I redirect from my web site -> Not ok.
same test with a copy of the directory at the Nitrogen application root and access from my web site -> not ok
As the information on the web page is ambiguous, I modified test.html to access to a file that does not exist on my PC -> same behavior.
I think I'll use the debugger to understand how the request is managed, to be continued...
Edit 2:
using the debugger I can verify that the wf_core:run_catched() is called several times. The fist call is when it process the event in my page that redirect to the static file.
The second time to process the static html file itself.
A third time to process finish_static_request() with a Path equal to my_music/song.ogg, and then I get lost in the processing of the answer. Another wf_core:run_catched() was called in parallel, but I didn't follow it...
I have been able to verify that the file can be accessed: I have added several audio tag in the html files, and I was able to "download" the existing files using the DownloadHelper Firefox plugin.
My understanding now is that the path is correct (at least when I place the files in a subdirectory of site/static), the server is able to retrieve the files and send them, the browser recognize the audio and video tags, but the link between the embedded audio/video reader and the files is lost, although I have added a type definition inside the audio tag.
Any idea to continue?
Edit 3:
Finally I got it. As Chops suggest it I had to go in the inets server configuration, not to define the path, but to define the type association. I have added the following definitions in etc/inets_httpd.erlenv, and it works.
{mime_types, [
{"css", "text/css"},
...
{"ogg","audio/ogg"},
{"webm","video/webm"}
]}
:o)
Based on the contents of the url attribute ("../../My Music/subdir/song.ogg"), the problem, when it's served from Nitrogen is that the request (Assuming you're using the default 127.0.0.1:8000) for the audio will be to the url "http://127.0.0.1:8000/My Music/subdir/song.ogg"
What you want to to do, if you're using the standard Nitrogen installation, is to put the song files you want into the site/static directory, perhaps in "songs" subdirectory.
Then change the url attribute to be "/songs/mysong.ogg" (or whatever path within site/static you used).
Note: Dependinding on your server choice (Webmachine, for example), you may need to tinker with the server's specific config file to tell it to handle the new directory for static paths, for help, check the configuration docs on the Nitrogen site.
Beyond that, there's nothing special about outputting raw HTML in Nitrogen. It is my understanding that the problem here is really just related to the paths of the requests being sent to the server.

Opening a Local PDF file in Browser using JSP

I have tried to open a PDF file from the local disk.
For example the Location is:
E:/files/IT/cat1/cat1Notification.pdf
But during runtime the link changes to:
http://localhost:8080/Office_Automation/E:/files/IT/cat1/cat1Notification.pdf
How to do i get rid of http://localhost:8080/Office_Automation/ from the link and open the file?
I have used
click here
To open the local file you need to use the file scheme in your URL
As you path is a Windows path E:/files/IT/cat1/cat1Notification.pdf, the link's href needs file:/// added before the your jsp's <%=path%> variable, so that the browser knows it needs to open a local file on the user's machine.
So your link should look like this
click here
Which in your browser will resolve to file:///E:/files/IT/cat1/cat1Notification.pdf
Without the file scheme the browser assumes that your link is relative to the webpage and tries to resolve the link by making a request to your webapp. This is why you were getting http://localhost:8080/Office_Automation/E:/files/IT/cat1/cat1Notification.pdf

rails: emulate "Save page as" behaviour

for a rails project I need to provide the user with a downloadable HTML version of a statistics page. I got so far as creating a controller action that will set the header as follows and then render and return my vanilla html page:
headers["Content-Type"] ||= 'application/x-unknown'
headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
This will make the browser pop open the download dialog instead of rendering the html right away, which is desired. However, this only gives me the blank HTML without any images or css embedded.
What I'd like to do is essentially the same thing that the browser does when you click on the "Save Page as" menu item (probably even zip images, css and html file up in a zip file and return that).
What's the right way to do this? Is there a way to invoke the browser "Save page as" dialog with a header setting?
Regards,
Sebastian
Here is a procedure that might work...
Assemble the things to be downloaded -- the rendered HTML, images, CSS, etc. -- into a staging dir on the filesystem.
Give the dir a definitely unique name (use timestamp maybe).
You could put the rendered HTML file in the dir root, and the assets in an assets subdir.
You'll need to modify all the asset item URIs in the HTML file to point to the item in the assets dir instead of its usual location. For example:
<img src='assets/my_img.jpg'>.
Zip it up into a *.zip archive using the rubyzip gem.
Use Rails's send_file method to open up a download dialog.
send_file '/path/to.zip'
Delete the staging dir and zip archive. Avoid deleting it while user is downloading. Perhaps set up a cron job to clean up once a day.
Could you try setting the HTTP content type to "application/octet-stream" and let me know if that helps?
Worked for me:
send_data(render, :filename => "filename.ext")