I have program which has webBrowser component. I need that this component would navigate to page which is in Resources ("1.htm"). Is there anyway to do it? My general wish is that after debuging I would have only one .exe file of program, and all htm pages would be build in it (like pictures and icons), or isnt that posible?
You can use DocumentText property for that
webBrowser1.DocumentText = WindowsFormsApplication1.Properties.Resources.1htm;
or
using (Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("1.htm"))
{
using (StreamReader reader = new StreamReader(stream))
{
webBrowser1.DocumentText = reader.ReadToEnd();
}
}
Related
i am trying to set an image in to a razor page in MAUI Blazor.
In MAUI (only), there was the aproach, that you have a .svg image in the folder Resources/Images. MAUI then converts the .svg image in a .png image which you can use in the XAML file. like so:
Now i have the same picture in a MAUI Blazor app and i hoped that i can put my picture in the same way expect that i have to use the HTML style like so:
<img src="one_list2.png">
But this doesn't work at all. I tryed with or witout path, path with slashes, backslashes etc. nothing works.
Trying to put a .png image into the wwwroot folder works. But this isn't the goal. I found it very nice to put a svg image which is then converted into a png depending of its size. This way all pictures would be converted exactly in the perfect size you will need lossless.
Thanks
First, Add the image to Resources\Raw and set it to MauiAsset compilation type
Second, Check the project file to avoid setting the image in the other folder.
In razor component HTML:
<img src="#imageSource">
In the code part:
private string? imageSource;
protected override async Task OnInitializedAsync()
{
try
{
using var stream =
await FileSystem.OpenAppPackageFileAsync("testimage.png");
using var reader = new StreamReader(stream);
byte[] result;
using (var streamReader = new MemoryStream())
{
stream.CopyTo(streamReader);
result = streamReader.ToArray();
}
imageSource = Convert.ToBase64String(result);
imageSource = string.Format("data:image/png;base64,{0}", imageSource);
}
catch (Exception ex)
{
//error
}
}
More information you can refer to ASP.NET Core Blazor Hybrid static files.
Is there any option to Open a PDF file that is available in local state folder (inside app installation directory) with the page number. There is one method (launchFileAsync) to open such files but I don't find any option to pass page number/index to open specific page.
Thank you! Any help is appreciated.
UWP provides the PdfDocument class for parsing PDF files, and this class provides the GetPage method for obtaining the object of the corresponding page (PdfPage) through the index.
This is simple code:
PdfDocument pdfDocument;
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("xxx.pdf");
pdfDocument = await PdfDocument.LoadFromFileAsync(file);
using (var firstPage = pdfDocument.GetPage(0))
{
var stream = new InMemoryRandomAccessStream();
await firstPage.RenderToStreamAsync(stream);
// do something...
}
Here is the complete code example:
PDF document sample
I can't figure out how to programatically add a view into a layout or page.
I need to add views at runtime without using static xml declaration since i need to fetch them from an http requested object... . I didn't find useful informations in the docs.
Anyone knows how to do?
I think you meant to dynamically add some view / controls to the page rather than to navigate into another page.
If so, you just need to add some controls into one of the layouts in your page (only containers [=layouts] can have multiple children.
so, your code (viewmodel/page controller) would look something like:
var layout = page.getViewById("Mycontainer");
// create dynamic content
var label = new Label();
label.text = "dynamic";
// connect to live view
layout.addChild(label)
In addition to having a page included inside your app (normal); you download the xml, css, & js to another directory and then navigate to it by then doing something like page.navigate('downloaded/page-name');
you can also do
var factoryFunc = function () {
var label = new labelModule.Label();
label.text = "Hello, world!";
var page = new pagesModule.Page();
page.content = label;
return page;
};
topmost.navigate(factoryFunc);
https://docs.nativescript.org/navigation#navigate-with-factory-function
You should check out this thread on the {N} forum.
The question is about dynamically loading a page and module from a remote server. The (possible) solution is given in this thread.
I am trying to display an Ajax returned xml file in String format in IE9.
Since it is in String, IE takes all xml tags as un-recognizable html tags and tosses them away. Only text data are display and it is really a mess. I can use <xmp> or <pre> but then when I save the xml by the file->save as..., the <xmp> <pre>is there. I do have the option to select all from the web page and copy paste to some text editor but in my case it is preferrable to use save as.
So I tried to escape all those < and > with entity reference in Java with StringEscapeUtils.escapeXml(). But still the problem persists. Do I have it right in Java? And is there any simple way to display xml input stream (not a file) as-is in a brwoser?
Here is the Java code for Ajax service.
public String retrieveXML() {
String unescapedXML = getXMLByRestfulService();
formatXMLMsg(unescapedXML);
String finalXML = StringEscapeUtils.escapeXml(unescapedXML);
return SUCCESS;
}
Here is the Ajax client code. Some parameters can be safely ignored.
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();a
} else if ( window.ActiveXObject ){
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if ( req ) {
req.onreadystatechange=function(){
if ( req.readyState == READY_STATE_COMPLETE ){
var myXML = req.responseText;
var myWin = window.open("", "aWindow", "width=800, height=500");
myWin.document.write("<xmp>"+myXML+"</xmp>");
myWin.focus();
}
};
req.open("POST", url, true );
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send (params);
}
I'm a little unclear on your question in regards to "as is" in browser. But, I'll take a shot.
You may need to enable the XML DOM plugin.
Click Tools(gear icon)->Manage Add-ons; this will pop-up a dialog
select "All add-ons". I don't have IE9 loaded, but you need to (may look like below):
Find "XML DOM Document" add-on and make sure its enabled
Close all IE windows and retest
is there a way to test wether a link was opened in a new browser-window (or browser-tab)?
Update:
So far I used the following code:
var newBrowserWindow = Browser.AttachTo<IE>(Find.ByTitle(browserTitle));
Assert.That(newBrowserWindow.hWnd, Is.Not.EqualTo(existingBrowserWindow.hWnd));
Where I used the existingBrowserWindow to open a page and to click on a link. But when the link opens a new tab in the existing browser (default behaviour for IE with targer=_blank) it has the same window-handle, since it's the same browser window. So how can I detect a new tab?
Some code of yours would help...,
Anyway, what I do when a link open a new browser window is
using (var newBrowser = WatiN.Core.Browser.AttachTo<IE>(Find.ByTitle("Analytics - Read conversation"))
{
}
Browser.AttachTo supports Find.ByUri(), Find.ByTitle() and Find.By("hwnd", windowHandle) according to documentation. I only tested Find.ByUri() and Find.ByTitle() methods.
if you want to detect if you action has opened a new window you could do
public bool TryGetNewBrowser(out IE browser, string title)
{
try
{
browser = WatiN.Core.Browser.AttachTo<IE>(Find.ByTitle(title));
return true;
}
catch(WatiN.Core.Exceptions.BrowserNotFoundException)
{
browser = null;
return false;
}
}
As far as I know, there is no support in WatiN for new tab. But the default behavior of internet explorer is to open new links in new window.