0

i am using this code.

C# Code Here i was attached the html ,c# and xaml code . Can you please refer this

private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                string curdir = Directory.GetCurrentDirectory();
                webBrowser.Navigate(String.Format("file:///{0}/sample.html", curdir));         
            }
            private void btngetdatafrombrowser_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    dynamic objdata = webBrowser.InvokeScript("GetData");
                    if (objdata != null)
                        MessageBox.Show(objdata);
                }
                catch (Exception ezx)
                {

                }
            }

    <!DOCTYPE html>
    <!-- saved from url=(0014)about:internet -->
    <html oncontextmenu="return false" ;>
    <head>
        <title>Testing</title>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11,IE=9; IE=8; IE=7; IE=EDGE" />
        <link rel="stylesheet" type="text/css" href="style.css">

    </head>
    <body> 
        <center>
            <form>
                <fieldset class="account-info">
                    <label>
                        Select the File
                        <input type="file" id="inputfile" onchange="ReadFile()" />
                    </label>

                </fieldset>

            </form>
        </center>
           <script>
            //Get Sample Function
            function GetSampleFunction() {
                return "Bala";
            }
            //Property Variable
            var rawData = undefined;
            var fr;
            //GetData For Select File
            function GetData() {
                          return "data";
            }
            //read data for select File
            function ReadFile() {
                var upload = document.getElementById('inputfile');
                var f = upload.files[0], read = new FileReader();
                fr = new FileReader();
                fr.onload = function () {
                    rawData = fr.result;
                };
                fr.readAsArrayBuffer(f);
          }


        </script>
    </body>
    </html>

      <WebBrowser x:Name="webBrowser" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" ObjectForScripting="HtmlInteropClass" Navigated="webBrowser_Navigated" Navigating="webBrowser_Navigating">
                <WebBrowser.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-0.018"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </WebBrowser.RenderTransform>
            </WebBrowser>
            <Button Grid.Row="1" Name="btngetdatafrombrowser" Click="btngetdatafrombrowser_Click" Background="SkyBlue" Foreground="White" FontSize="34">Getdata</Button>

But i don't want to use this.its possible to do this in wpf application without using web browser control.

this thing happens by using web browser control but it should done without using the web browser

sugar kavi
  • 21
  • 1
  • 5
  • In the provided code you are not executing any script, you are just reading the html content and displaying on the message box. This can be simply done by reading the html file content – PSK Mar 28 '18 at 06:53
  • GetData is my function in script.here i am reading html file using web browser,but i want to read it without using web browser control.its possible please share some sample. – sugar kavi Mar 28 '18 at 07:06
  • What do you mean by "read it" - only show html content (unrendered, as "source code" ) ? Then you can simply do a http get with for example WebClient. – Fildor Mar 28 '18 at 07:16
  • Read this https://en.wikipedia.org/wiki/Rhino_(JavaScript_engine) – PSK Mar 28 '18 at 07:17
  • Possible duplicate of [How I can get web page's content and save it into the string variable](https://stackoverflow.com/questions/4510212/how-i-can-get-web-pages-content-and-save-it-into-the-string-variable) – Fildor Mar 28 '18 at 07:18
  • please refer my code i have updated my question brief – sugar kavi Mar 28 '18 at 07:31
  • The html and javascript are just representative? The javascript in the page is supposed to work? I'm not clear why the webbrowser control is bad, please explain why. Is showing it in a separate browser ( the machine default ) acceptable? – Andy Mar 28 '18 at 07:56
  • its ok, but i need to know whether its possible to do without web browser and how to do it. – sugar kavi Mar 28 '18 at 09:09

0 Answers0