Click here to Skip to main content
13,740,862 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, my code working fine local but i am hosting this project not show data
please help me..


private void CallBatocTransIndia()

            string url = "";
            Thread thread = new Thread(delegate()
                using (WebBrowser browser = new WebBrowser())
                    browser.ScrollBarsEnabled = false;
                    browser.AllowNavigation = true;
                    browser.Width = 1024;
                    browser.Height = 768;
                    //browser.Document.GetElementById("txtLrNo").SetAttribute("value", "15470038610");
                    browser.ScriptErrorsSuppressed = true;

                    browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
                    browser.ProgressChanged += new WebBrowserProgressChangedEventHandler(ProgressChanged);
                    while (browser.ReadyState != WebBrowserReadyState.Complete)


                        //gg.InnerHtml = browser.Document.Body.InnerHtml;


        long ff = 0;
        private void ProgressChanged(Object sender, WebBrowserProgressChangedEventArgs e)
                HtmlDocument doc = ((WebBrowser)sender).Document;
                if (e.MaximumProgress == 10000)
                    ff = e.MaximumProgress;
                if (e.CurrentProgress > e.MaximumProgress)
                    if (e.CurrentProgress == 10000)
                        //string m1 = doc.Body.OuterHtml;
                        ////string m2 = GG.InnerHtml;
                        ////string m3 = GG.InnerHtml;
                        //int indexF = m1.IndexOf("LDM Details");
                        //int f = (m1.Length - indexF);
                        //string m11 = m1.Remove(indexF, f);
                        //gg.InnerHtml = m1;
                        //string varstr = doc.Body.OuterHtml;
                        //int indexf = varstr.IndexOf("Transit Details");
                        //int indexE = varstr.IndexOf("Top");
                        //gg.InnerHtml = doc.Body.OuterHtml;

            catch(Exception ex)
                // browser.Navigate(txtUrl.Text.Trim());

        private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            string Lrno;
           // Response.Write("<script>alert('Hello');</script>");
            Lrno = Request.QueryString["Lrnostr"];
                HtmlDocument doc = ((WebBrowser)sender).Document;
                string g = e.Url.ToString();

                if (g == "")

                    doc.GetElementById("txtLrNo").SetAttribute("value", "154700" + Lrno);
                    flag = true;

                    //Response.Write("<script>alert('Hello In');</script>");

                    string varstr = doc.Body.OuterHtml;
                    int indexf = varstr.IndexOf("Transit Details");
                    int indexE = varstr.IndexOf("Top");

                    string Main = "<table>" + doc.Body.OuterHtml.ToString().Substring(indexf, (indexE - indexf)) + "</table>";
                    //int indexEtr = Main.IndexOf("LDM Details");
                    int indexEtr = Main.IndexOf("</TABLE>");

                    string TrDt = Main.Substring(0, (Main.Length - indexEtr));
                    string LdmDt = Main.Substring(indexEtr, (Main.Length - indexEtr));
                    int indexCashdt = LdmDt.IndexOf("Cash Memo Details");
                    string LdmDt1 = LdmDt.Substring(0, (indexCashdt));

                    BTPLTrans.InnerHtml = Main; // "<table>" + TrDt + "</Table>" + "<table>" + LdmDt1 + "</table>";

               // browser.Navigate(txtUrl.Text.Trim());


What I have tried:

Not show data in hosting server
Posted 10-Nov-17 0:20am
Updated 10-Nov-17 17:36pm
Suvendu Shekhar Giri 10-Nov-17 6:30am
Well, what error are you getting?
Have you enabled error logging/tracing/anything?
Priyam2012 10-Nov-17 8:26am
not show any error...
F-ES Sitecore 10-Nov-17 7:03am
Code like this rarely works on, it only worked on your local machine probably because you were using your own account to run your code, it wasn't in a multi-user environment, or a million other factors. If you're determined to unethically use a third party website and present it as if it is your own work then you'll need to learn another way of doing it that will work from code.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This code will not work in an ASP.NET application. The WebBrowser control MUST be used in a Windows Forms app WITH A WINDOW!

I'm sure you got it to work on your machine because the code was running as YOU when you debugged it in Visual Studio. It will NOT work when deployed to a web server where the code will never have a window and is running as a service account.

You have to scrap this code and rewrite it using some other method to "scrap" the website you're trying to get data from. Perhaps the WebRequest and HttpWebRequest class would work for you. I suggest Google for those and start reading to find out how to use them.
Priyam2012 10-Nov-17 13:51pm
Thanks for reply
ok instoll visual stdio in my VPN server then code work ?
Dave Kreskowiak 10-Nov-17 14:06pm
What the hell does that have to do with anything?

No! The code will NEVER WORK in a hosted ASP.NET application!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100