Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Logging to Website

Logging to Website

Scheduled Pinned Locked Moved C#
csharpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NaveenHS
    wrote on last edited by
    #1

    Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.

    L L B 3 Replies Last reply
    0
    • N NaveenHS

      Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Can you please elaborate more on your question so that it is easier to answer it? What you are trying to download and from which site using csharp ? HTH

      Jinal Desai - LIVE Experience is mother of sage....

      N 1 Reply Last reply
      0
      • L Lost User

        Can you please elaborate more on your question so that it is easier to answer it? What you are trying to download and from which site using csharp ? HTH

        Jinal Desai - LIVE Experience is mother of sage....

        N Offline
        N Offline
        NaveenHS
        wrote on last edited by
        #3

        Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??

        K L 2 Replies Last reply
        0
        • N NaveenHS

          Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          you want the HttpWebRequest and HttpWebResponse classes, and the Credentials property. Use Google to get lots of examples. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          • N NaveenHS

            Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??

            K Offline
            K Offline
            karmjit435
            wrote on last edited by
            #5

            Hi Naveen, you can study WebClient class. http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx

            1 Reply Last reply
            0
            • N NaveenHS

              Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.

              B Offline
              B Offline
              Bigdeak
              wrote on last edited by
              #6

              I have the same problem to login to a website, therefore i have only a half answer. I know 4 methods to download informations from a website. 1. System.NET.WebClient This is a native Client class to download Data or the html string from a internet adress.

              WebClient webClient = new WebClient();
              webClientData = webClient.DownloadData(uri);

              as far as i know it is possible to login to a website with this class, but i never have find out how. 2. System.Windows.Forms.WebBrowser This is a internet explorer class for the framework. You can login to a website, because it uses the variables/cookies/etc. from the internet explorer. 3. System.NET.WebRequest In this class it's possible to use POST and GET, this is needed to login to a website, but i don't know how to POST login informations, i only know how to donwload the data from a website.

              byte[] buffer;
              HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
              HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
              System.IO.Stream s = resp.GetResponseStream();

              4. TCP Socket Yes, this protocol bases upon to TCP, you can connect to the website and communicate over the Hypertext Transfer Protocol with the website. If you need more informations about the methods, you can use google. I hope i could help you a bit and sorry for my bad english.

              1 Reply Last reply
              0
              • N NaveenHS

                Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Find following code useful for the same.

                private void DownloadFile( string fname, bool forceDownload )
                {
                string path = MapPath( fname );
                string name = Path.GetFileName( path );
                string ext = Path.GetExtension( path );
                string type = "";
                // set known types based on file extension
                if ( ext != null )
                {
                switch( ext.ToLower() )
                {
                case ".htm":
                case ".html":
                type = "text/HTML";
                break;

                case ".txt":
                  type = "text/plain";
                  break;
                 
                case ".doc":
                case ".rtf":
                  type = "Application/msword";
                  break;
                }
                

                }
                if ( forceDownload )
                {
                Response.AppendHeader( "content-disposition",
                "attachment; filename=" + name );
                }
                if ( type != "" )
                Response.ContentType = type;
                Response.WriteFile( path );
                Response.End();
                }

                Also find following link useful... Downloading a File with a Save As Dialog in ASP.NET[^] HTH

                Jinal Desai - LIVE Experience is mother of sage....

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups