Load HTML file using MonoDroid - c#

I want to load an local html file as part of my Help Screen. I have placed the file "test.html" in my Assets folder.
Here is my code:
WebView web_view;
web_view=FindViewbyId<WebView>(Resource.Id.webview);
web_view.Settings.JavaScriptEnabled=true;
web_view.LoadUrl("file://test.html");
I am getting a "Web page not available" error.
Thanks in advance. TB

web_view.LoadUrl("file:///android_asset/test.html);
Use this line instead of that

web_view.LoadUrl("file:///test.html);
Use this line instead of that because use "file:///" not "file://" please change and after Run.

Related

How do i load html from a db and display images that are stored locally in the project

I am storing the content for my page in a sql server database. When i load the content onto the page i have a tag:
<img src="~/Images/Course/html.jpg" />
The html is being rendered using #Html.Raw(content).
when the page loads i get the error:
GET http://localhost:51249/Course/Index/~/Images/Course/html.jpg 404 (Not Found)
I dont know why it does this. Is there any way to have images stored in files within the project, then when loading the html from the db the local linking works? Do I have to host the images somewhere and link to them via https? Any help would be great.
Fixed it - just remove the tilda from the value in the database. Here's a small sample code in the HTML to reproduce the same problem:
<img src="~/images/house.jpg" />
#{
var something = "<img src='/images/house.jpg' />";
}
#Html.Raw(something)
The first line displays the image direct from the location, using the tilda, which .net resolves to the root of your project.
The second line doesn't use the tilda, which automatically comes from the root of the project, but leaving the tilda in messes up.
Fix: delete one character from the HTML stored in the database.

Drawing an SVG File in WinRT

I'm trying to draw a SVG File. So far I've tried using an Image tag and a WebView with the svg itself or an object / embed tag. Nothing so far seems to help, and all the dll's I've found so far need .NET.
Examples of what I've tried so far (note: Paths have all been tried with or without ms-appx:///, note2: using img tag in webview for non-svg types hasn't worked either)
WebView:
webView.NavigateToString("<embed src='circle1.svg' type='image/svg+xml' />");
webView.NavigateToString("<object data='circle1.svg' type='image/svg+xml' />");
webView.NavigateToString("<svg>....</svg>");
Image:
<Image Source='circle1.svg'>
I am not sure if you can include external images this way, have you tried with other image formats? Have you tried using an absolute path? I would also consider using the data tag as image source instead of an external file.
Example (from wikipedia):
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
alt="Red dot">
Additionally, there is project in codeplex called xamltune that can convert a svg file into an xaml file. Maybe you can insert the output xaml code in your application instead of using a WebView.

ASP.Net Hyperlink navigation URL not including server name

This might be a ridiculously easy question, but it has me stumped. I have a web form where I'm trying to create a hyperlink in the code behind to a file server share, e.g. file://myServer/Shared/, but when the page is rendered, the link doesn't include the server name, i.e. file:///Shared/. I don't know why this happens. Any help or insight is appreciated.
UPDATE:
Sure, here is the snippet where the link is being set.
//The link is embedded in a table
HyperLink link = (HyperLink)e.Row.Cells[1].Controls[0];
link.NavigateUrl = #"file://myServer/Shared/";
As a test, I assigned the link to a string value and the link prints the expected url.
string foo = link.NavigateUrl;
//Displays this
"file://myServer/Shared/"
I don't know why this doesn't appear when the link is rendered in the final page.
UPDATE 2:
Ok, so I know I have to set the absolute path in the code-behind, I thought that's what I was doing, but it still won't render correctly.
UPDATE 3:
I followed pjacobs suggestion about setting the test property and it was actually a step in the right direction. I have the following:
link.Text = "link text";
Now the link gets rendered as follows: file:///myServer/Shared. I'm almost there except it gives the extra '/' in front of the server name. I'll keep playing with it, this seems like it should be so simple, I don't understand why ASP.Net renders the URL differently.
You have to set the Text property of the HyperLink... link.Text = "whatever"
Are the resources inside the project? If so:
you need to use ResolveUrl to resolve the "web location" of the resource.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx
if you're using an asp.net control you shouldn't need to use the resolve url, but you need to refer to the location of the file relative to the path of the project.
If not:
Did you give the proper read account to ASP.NET process?
Use a virtual directory?
http://www.dotnetspider.com/tutorials/AspNet-Tutorial-86.aspx

redirect to an image

Why can't I redirect page to a image for example:
Response.Redirect("http://www.domain.com/images/image.gif");
This doesn't show me the image. Also placing conten type image/gif doesn't show the image.
Works for me. I created an "images" folder and added the following to the Page_Load method of my Default.aspx page:
Response.Redirect("~/images/scenery.jpg");
try relative path, not a complete url
meaning Response.Redirect("images/image.gif");

How to reference embedded images from CSS?

I have a CSS file that is embedded in my assembly. I need to set a background image for certain elements using this CSS file, and the image needs to be an embedded resource also. Is this possible? Is there any way I can reliably do this?
I ran into the problem when putting an existing stylesheet into this dll then realized images weren't showing up. I don't know of any way to make it work though because I would need to know the URL to the embedded image.
Has anyone done anything like this?
<% = WebResource("image1.jpg") %>
You can use above statement inside your CSS file, and while you register your CSS with
WebResourceAttribute, you can set "PerformSubstitution" to true
Default.css
body{
background: <%=WebResource("xyz.jpg")%>
}
[assembly, WebResource("Default.css","text/css", PerformSubstitution=true)]
[assembly, WebResource("xyz.jpg","image/jpg")]
Just follow the following steps to refer a web resource as background Image in CSS
Refer Image URL as "background: url('<%=WebResource("xyz.jpg")%>');" in following manner.
Default.css
body{
background: url('<%=WebResource("xyz.jpg")%>');
}
In AssemblyInfo.cs file register the CSS file with "PerformSubstitution=true" attribute in following manner
[assembly, WebResource("Default.css","text/css", PerformSubstitution=true)]
Now again in AssemblyInfo.cs file register the image file as
[assembly, WebResource("xyz.jpg","image/jpg")]
Right Click the Image File (xyz.jpg) and CSS File (Default.css) and click on Properties now select "Build Resource" option as "Embedded Resource".
and its done.
Happy Coding !!!
Mine is a slight variation on the other suggestions but it works for my inline CSS within my ASP.NET page
Add the following entry to the AssemblyInfo.cs file - [assembly: WebResource("MyImageFile.png", "image/png")]
add the following code within the CSS to reference the embedded resource - background-image: url('<%= Page.ClientScript.GetWebResourceUrl(typeof(MyUserControl), "MyImageFile.png") %>')
What about exposing the resources through a Web service?
Such as in the CSS file, set background: url( getImage.aspx?image=newyork.jpg )?

Categories