Powered By Blogger

C#SHARP ANSWER

Tuesday, May 31, 2011

configuring the c# compiler

Transcend 4 GB Class 6 SDHC Flash Memory Card TS4GSDHC6
Before you can begin to make use of the c# command line compiler,you need to ensure that your development machine recognizes the existence of csc.exe.Ideally, csc.exe is configured correctly at the time you install .NET SDK. However ,in my experiences teaching various .NET classes,I have found out the hard way (typically during the first code demo) this is not always the case . If  csc.exe is not configured correctly ,you are forced to change to the directory containing csc.exe before you can compile your program ( which is massive pain in the neck, given that you must type in the full path name to the *.cs files to be compiled ).
     To equip development machine to compile *.cs files from any subdirectory, follow these steps
  • Right-click the My computer icon and select properties from the pop up menu.
  • select the advanced tab and click the environment variable button.
  • Double click the path variable from the system variable list box.
  • Add the following line to the end of the current value (note each value in the path variable is separated by a semicolon) :\%windir%\Microsoft.NET\Framework\v1.1.4322
ofcourse the exact path name may need to be adjusted based on your current version and location of the .NET SDK (so be sure to do sanity check). once you have
added the correct path setting, you may take a test run by closing any command windows open in the background ( to commit the settings),then open a new command window and enter csc -?
If you set things up correctly,you should see a display of each option supported by the raw c# compiler

Sunday, May 29, 2011

c# code to extract source of web page


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
        // used to build entire input
        StringBuilder sb = new StringBuilder();

        // used on each read operation
        byte[] buf = new byte[8192];

        // prepare the web page we will be asking for
        HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create("http://www.google.co.in/search?hl=en&biw=772&bih=493&q=operating+system&oq=operating&aq=0&aqi=g10&aql=f&gs_sm=e&gs_upl=6031l10625l0l9l8l0l1l1l0l359l1202l2-1.3");

        // execute the request
        HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();

        // we will read data via the response stream
        Stream resStream = response.GetResponseStream();

        string tempString = null;
        int count = 0;

        do
        {
            // fill the buffer with data
            count = resStream.Read(buf, 0, buf.Length);

            // make sure we read some data
            if (count != 0)
            {
                // translate from bytes to ASCII text
                tempString = Encoding.ASCII.GetString(buf, 0, count);

                // continue building the string
                sb.Append(tempString);
            }
        }
        while (count > 0); // any more data to read?

        // print out page source
        System.IO.StreamWriter file1 = new System.IO.StreamWriter("D:\\test.txt");
        file1.WriteLine(sb.ToString());
        file1.Close();