2

This will probably sound dumb, but I need to execute a C# code from my html file. For example I just want to execute this

System.Diagnostics.Process.Start(@"D:\Movies\HurtLocker.avi");

Not any server side code.

I can't create aspx page, because to open an aspx page in a browser it needs to be hosted in IIS.

3
  • I think your question is really, "How do I create a web page that allows the viewer to watch a video?" Commented Jan 12, 2011 at 11:56
  • @David it is just an example, you can tell I just want to use .net libraries on my html file. Commented Jan 12, 2011 at 12:00
  • If it were possible, what's to stop someone from trying to start the process format.exe? Commented Apr 2, 2014 at 17:58

7 Answers 7

3

You can't execute server side code from a client side page. If your page is aspx you can use a webservice or click a serverside button from javascript.

Edit: If you want to embed a video player please check this link. You don't need server side code for this. You'll be able to do it with javascript.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanx pabuc. I Updated the question, Please check it.
My answer will stay same. No valid way of doing this on a html page. If you are trying to play a movie on your static page (html), you can do this in many ways. Is this what you want?
2

Where do you want the c# code to run?

If you want it to run in the browser that is being used to render the html then I'd say that was basically not possible. Something, presumably javascript code in the html page, would have to somehow instantiate a .net clr and pass the c# code to it for execution. The clr does have a COM-based hosting interface that would allow instantiation, but even if you could call this from javascript I think that any sensible browser security settings would prevent it.

If you want the c# to run on the server supplying the html page then you should use asp.net.

EDIT

Ok, you want to run it in the browser. I'm not aware of any examples for hosting a clr in the browser process, sorry.

You can create activex/com objects in js using something like var obj=new ActiveXObject("<comclassname>");, and you might be able to create a CLR that way by instantiating one of the COM classes (maybe CLRRuntimeHost) listed on this page. You could then pass your c# code to your clr for execution. More info here and here. I'm really not sure if that would work, though. I've never used the hosting api, I just know it exists!

Seems like an interesting project to try if you are curious, but deploying this in a real environment would likely present lots of problems. Good luck!

1 Comment

Thanx Andy, I agree with you, I would really like to try calling .net CLR from javascript can I have any example?
1

Not C#, but how about .NET dynamic language in the browser with Gestalt? http://gestalt.codeplex.com/

Comments

0

You can create a code block in your ASP file but if this is simple HTML file this is not possible.

At least you will have some application that will read the content of the page compile it and execute.

ASP code block

Comments

0

As Pabuc mentioned you can't execute server side code on the client machine in HTML. If you were to use Silverlight you could execute the code client side, but then the client need to have Silverlight installed and it is not strictly HTML anymore.

Silverlight could be used to play movies client side with C#.

Comments

0

The only way to have C# on client side is Silverlight application [update] or any other browser plugin as @kenny mentioned.

Comments

0

I have tried to find a software for this some time. I have software, which has needs, that are hard to make with traditional Web programming.

Now I have made simple demo, how to create HTML5 online application with C# or VB.NET. It is Scot library which translates C# to Javascript on time when executing .NET application. It also supports events on Browsers, which is executed in c# code.

To original question:

On the Html page you will need to add single line after :

<script src="myclass.cs"> </script>`

to connect .Net class:

using Scot;
//..
public myclass:Document
{     
    protected override OnConnect()     
    {        
        Elements["mybutton"].OnClick+=new JsInputEventHandler(click); 
        //your initialization        //....     
    }     
    private void click(object sender, JsInputEventArgs e)     
    {        
        Window.Alert("Click()");     
    } 
}

Demos are quite simple, but actually I needed this library for another project. It would be nice to have any feedback.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.