C# WebBrowser not loading local Javascript file - c#

I am using the C# WebBrowser control. My HTML renders fine. However, I need to keep external files on the local computer. References to the local copy of files do not work.
How do I write the HTML to load locally stored files?
This works:
<script type='text/javascript' src='https://code.jquery.com/jquery-latest.min.js'></script>
This works when loading a file directly in to a browser, but not through the C# WebBrowser control:
<script type='text/javascript' src='./jquery-latest.min.js'></script>
Adding the full path gets rid of error messages, but still does not work.
<script type='text/javascript' src='file:///C:/<full path>/jquery-latest.min.js'></script>
I have tried adding this to the first line of the html file which does not solve the problem.
<!-- saved from url=(0014)about:internet -->

Just put your local js file in the same directory with your html file. Then use this will do
<script type='text/javascript' src='./jquery-latest.min.js'></script>

Related

How to use the Monaco editor inside a Windows Forms application?

I have a windows form app (.net framework) and I want to use Monaco editor inside it. Scouring the internet does the provide much help and stackoverflow does not have the same questions either. I don't know many apps that use Monaco (which are not made by Microsoft) but the ones I know are:
KRNL
Synapse X
Please know that these are roblox cheats and were the only apps I could find which use the Monaco editor and are written in C#.
Since these apps are able to use Monaco there must be a way to use it with c#, right?
You can use a WebView2 control to show the Monaco editor in a Windows Forms Application, then you can have a code editor which supports editing the syntax-highlighted code which supports intellisense and much more.
Please note that the Monaco Editor no longer supports IE 11. The last version that was tested on IE 11 is 0.18.1.
To do so, follow these steps:
Create a Windows Forms Application (.NET, or .NET Framework)
Install Microsoft.Web.WebView2 NuGet package (The Monaco Editor no longer supports IE 11. The last version that was tested on IE 11 is 0.18.1)
Create a folder named MonacoEditor in your project.
Download Monaco editor from Monaco Editor site. (I tested by downloading version 0.33.0)
In the file explorer, open the Mocano folder, then extract the downloaded file and copy the min subfolder of extracted files into your Monaco folder.
Add index.html file to the Monaco folder in filesystem, with the following content:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet"
data-name="vs/editor/editor.main"
href="./min/vs/editor/editor.main.css" />
<style>
html, body { height: 100%; margin: 0; }
#container { height: 100%; }
</style>
</head>
<body>
<div id="container"></div>
<script src="./min/vs/loader.js"></script>
<script>
require.config({ paths: { 'vs': './min/vs' } });
</script>
<script src="./min/vs/editor/editor.main.nls.js"></script>
<script src="./min/vs/editor/editor.main.js"></script>
<script>
var editor = monaco.editor.create(document.getElementById('container'), {
value: 'function helloWorld() {\n\tconsole.log("Hello world!");\n}',
language: 'javascript'
});
</script>
</body>
</html>
Edit your project file, find the following section:
<ItemGroup>
<Folder Include="Monaco\" />
</ItemGroup>
And replace it with the following:
<ItemGroup>
<Content Include="Monaco\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
It basically includes all the files under the Monaco folder into the project and also copies them into the output directory.
Please note, for a .NET Framework project you need to first unload the project, and then after editing the project file, reload it.
Drop an instance of WebView2 on the form.
Handle the Load event of the form with the following code:
private void Form1_Load(object sender, EventArgs e)
{
this.webView21.Source =
new Uri(Path.Combine(Application.StartupPath, #"Monaco\index.html"));
}
Run the application and see the result, the code editor with syntax-highlighted code which supports intellisense.

What are the mechanics of producing bundled js and css files with master pages?

I have a .NET Core project in which the master page _Layout.cshtml page references site wide style and js files:
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/site.js" asp-append-version="true"></script>
The Index.cshtml page, which utilizes the above master page, references page specific style and js files:
<link type="text/css" rel="stylesheet" href="~/css/landing.css">
<script src="~/js/landing.js" asp-append-version="true"></script>
And then Contact.cshtml and About.cshtml also have page specific css and js files.
What is the correct method to bundle the site wide files with page specific files?
Should I avoid referencing anything the in the master page and simply reference the bundled file in each page's .cshtml?
You reference in your Master Page all scripts and Style Sheets you share across pages. For instance, you could reference only jquery.
You reference in your pages scripts and styles that are used specific on that pages.
It sounds simple like that.

PDF object not showing when HTML file is opened from visual studio

I have an HTML file that I am tinkering with attempting create a web form with functionality and have a PDF view embeded.
<!DOCTYPE html>
<html><head></head>
<body>
<object data="C:\test\PI.pdf" type="application/pdf" width="300" height="200"></object>
</body>
</html>
The PDF works fine when I open it from windows explorer or sublime text. It will have a URL in the browser that looks like this:
file:///C:/Users/dvandenbosch/Desktop/Visual%20Studio%20And%20General%20Programming/temp/scratchpad.html
When I open it from visual studio, it doesn't allow me to see the pdf. It is just blank. It has a URL that looks like this.
http://localhost:59478/scratchpad.html
Why is this?
I need to be able to show pdfs from my shared file drive on to our internal sharepoint using a web browser. Please help!

Render bundled scripts from app in Virtual Directory (VD) to an app in another VD

I have 2 projects ABC and XYZ created as 2 separate Virtual Directories in IIS (7). Now my problem is I have many .JS (script) files in project XYZ that need to be bundled and minfied and rendered in an aspx page (containing HTML code) that is available in project ABC. Is this possible ?
Note: Using Microsoft ASP.NET Web Optimization Framework 1.1.1
[http://www.nuget.org/packages/microsoft.aspnet.web.optimization/]
Yes, just use the correct link to the bundle in your other project.
If you bundle is for example defines as
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
which can get accessed via
#Scripts.Render("~/bundles/jquery")
you can use
<script src='http://<host>/<site>/bundles/jquery' type='text/javascript' language='javascript' />
Just as simple as that.
If you have both applications installed on the same website (same root), you can also use relative URLs, e.g.
<script src='/XYZ/bundles/jquery' type='text/javascript' language='javascript' />

EnableCDN in toolkitscriptmanager not downloading minified files

I have this ToolkitScriptManager in my Master page:
<asp:ToolkitScriptManager runat="server" EnableScriptGlobalization="false" ID="scrptManager"
LoadScriptsBeforeUI="false" ScriptMode="Release" EnableCdn="true">
</asp:ToolkitScriptManager>
Notice the ScriptMode="Release" and I have compilation debug="false" in my web.config
However, when the scripts get download to the client I get unminified javascripts. The ToolkitScriptManager downloads scripts from:
http://ajax.aspnetcdn.com/ajax/4.0/1/WebUIValidation.js
http://ajax.aspnetcdn.com/ajax/4.0/1/WebForms.js
How do I modify my ToolkitScriptManager to download minified version of these scripts?
This is just a theory. By check the following:
http://ajax.aspnetcdn.com/ajax/4.0/1/WebForms.js
vs
http://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js
I noticed the MicrosoftAjax.js file it is minified, however the WebForms.js file is not. I think your set up for the ToolkitScriptManager is correct and there are some issues with cdn conent. Again it's just a guess, to be sure, maybe you can ask on asp.net forums: http://forums.asp.net/
Hope this helps.

Categories