Apr 24, 2008

How to write text file using ASP?

How to write text file using ASP?

Previously I wrote for how to write text file with C#, Now one step back how to write text file with ASP?

So here we goes.

set FSO = Server.CreateObject("scripting.FileSystemObject")

This line creates an object that is used for File Access

set myFile = fso.CreateTextFile("C:\Trace.txt", true)

This creates a blank text file object for us to use.The CreateTextFile object creates a text file, based on what we specified. The first option specifies the location of the text file, while the second one states whether or not to create the file if one doesn't exist. Very simple methods.

Next, we do something simple

myFile.WriteLine("Write whatever you want to put")

myFile.WriteLine("Write some more stuff")

WriteLine writes the text to the text file.

myFile.Close

This closes the file and free the memory.

Now for Reading:

First, we create an object, but not after defining some constants

Const ForReading = 1, ForWriting = 2, ForAppending = 8

This just allows us the different methods of working with text, when we have an open text file.

set fso = server.CreateObject("Scripting.FileSystemObject")

Here we create our object again.

set f = fso.GetFile("C:\Trace.txt")

Here we state that we will be manipulating the file C:\Trace.txt . Moderately simple. Now we need to open it as a stream. Get ready, here comes the hard stuff ;-)

set ts = f.OpenAsTextStream(ForReading, -2)

This creates a text stream with our file. It is like a continous flow of information. Now we jsut read a line

TextStreamTest = ts.ReadLine

This code reads a line of information, and puts it into TextStreamTest. Pretty simple, isnt it?! I hope so. Anyway, I've discussed the code, and I shall let you go.

One last note. Let's say you wanted to read all the contents out a text file. Then you would do this

Do While not ts.AtEndOfStream

myText = myText & ts.ReadLine & vbCrLf

Loop

Hope you learn something !! Write your comments !! Thanks !!

Apr 23, 2008

Writing Log to Text File with C#

Writing Text File with C#

 

Problem definition : I need to write this for logging for testing purpose. I am logging the information when a aspx file is being called,

I want to put all information like browser, os, resolution, referer page etc.

 

So here we goes

I like to add a method let it call LogToFile()

Don't forget to include #using System.IO; as we are going to use stream writer

protected void LogToFile()

    {

            string logFilePath = Server.MapPath("Trace.txt");

        StreamWriter sw = new StreamWriter(logFilePath, true);

        //true means if file not there then create it otherwise append to it.

        try

        {

            sw.WriteLine("Logging Time: " + DateTime.Now.ToLongDateString());

            sw.WriteLine("OS/Browser/Version : "+Request.Browser.Platform.ToString()+"/" +Request.Browser.Browser.ToString()+ “/"+Request.Browser.Version.ToString());

           

            if (Request.UrlReferrer != null)

            {

                sw.WriteLine("Referrer: "+ Request.UrlReferrer.ToString());

            }

            sw.WriteLine("User Agent: " + Request.UserAgent.ToString());

            sw.WriteLine("--------------------------------------------------------");

        }

        catch(Exception )

        {

        }

        finally

        {

            if (sw != null)

            {

                sw.Close();

            }

        } 

    }

Now call this function into pageload method of your page... you will get the trace.

You can add more properties/ information according to your needs.

Apr 22, 2008

Enable pinging - Ping worker process every ( 30 seconds)

Application Pools setting

 

Enable pinging – Ping worker process every (frequency in seconds)

This setting specifies that each worker process will be pinged every n seconds, where n is the number specified in the selection box. This process is used to determine if a worker process is running correctly, or if it has been deadlocked.

What it mean ?

Central to Health monitoring is process pinging. With process pinging, IIS periodically checks to see if worker processes are responsive. This means that the WWW Service (svchost.exe) sends a ping request at a specified interval to each worker process (w3wp.exe). If a worker process fails to respond to the ping request, either because it doesn’t have additional threads available for processing incoming requests or because it’s hung up, the WWW Service flags the worker process as unhealthy. If the worker process is in an idle but unresponsive state, the WWW Service terminates it immediately and a replacement worker process is created. Otherwise, the worker process is marked for recycling.

 

Apr 17, 2008

Free Tax Calculator 2008 2009 India

In my previous post I could not upload the Tax Calculator, Here I did it and posted it again.

Please get if from HERE

Note this is for salaried personal only.

Tips on Filling your Vehicles

This is a Message received from a friend:

I don't know what you guys are paying for petrol... but here in Durban, we are also paying higher, up to 47.35 per litre. But my line of work is in petroleum for about 31 years now, so here are some tricks to get more of your money's worth for every litre.

Here at the Marian Hill Pipeline, where I work in Durban, we deliver about 4 million litres in a 24-hour period thru the pipeline.

One day is diesel; the next day is jet fuel, and petrol, LRP and Unleaded. We have 34-storage tanks here with a total capacity of 16,800,000 litres.

ONLY BUY OR FILL UP YOUR CAR OR BIKKIE IN THE EARLY MORNING WHEN THE GROUND TEMPERATURE IS STILL COLD. Remember that all service stations have their storage tanks buried below ground. The colder the ground, the denser the fuel, when it gets warmer petrol expands, so buying in the afternoon or in the evening.... your litre is not exactly a litre.

In the petroleum business, the specific gravity and the temperature of the petrol, diesel and jet fuel, ethanol and other petroleum products play an important role. A 1degree rise in temperature is a big deal for this business. But the service stations do not have temperature compensation at the pumps.

WHEN YOU'RE FILLING UP, DO NOT SQUEEZE THE TRIGGER OF THE NOZZLE TO A FAST MODE. If you look, you will see that the trigger has three (3) stages: low, middle, and high. In slow mode, you should be pumping on low speed, thereby minimizing the vapours that are created, while you are pumping. All hoses at the pump have a vapour return. If you are pumping on the fast rate, some of the liquid that goes to your tank becomes vapour. Those vapours are being sucked up and back into the underground storage tank so you're getting less worth for your money.

ONE OF THE MOST IMPORTANT TIPS IS TO FILL UP WHEN YOUR TANK IS HALF FULL. The reason for this is, the more fuel you have in your tank, the less air occupying its empty space. Petrol evaporates faster than you can imagine. Petroleum storage tanks have an internal floating roof. This roof serves as zero clearance between the petrol and the atmosphere, so it minimizes the evaporation.

Unlike service stations, here where I work, every truck that we load is temperature compensated, so that every litre is actually the exact amount.

ANOTHER REMINDER, IF THERE IS A FUEL TRUCK PUMPING INTO THE STORAGE TANKS, WHEN YOU STOP TO BUY, DO NOT FILL UP - most likely the petrol/diesel is being stirred up as the fuel is being delivered, and you might pick up some of the dirt that normally settles on the bottom.

Hope, this will help you get the maximum value for your money.

DO SHARE THESE TIPS WITH OTHERS! LET’S SHARE INFORMATION AND BENEFIT ALL, FOR THE BETTER OF MANKIND.

Apr 11, 2008

A wonderful message for all who misuse their work phone : Joke

Phone Bill

The phone bill was exceptionally high and the man of the house called a family meeting...

Dad: People this is unacceptable. You have to limit the use of the phone. I do not use this phone, I use the one at the office.

Mum: Same here, I hardly use this home telephone as I use my work telephone

Son: Me too, I never use the home phone. I always use my company mobile

Maid: I know I am the one to be blamed but  what is the problem? We all use our work telephones.

 

 

Apr 3, 2008

TAX Calculator for Financial Year 2008 - 2009

A quick tax calculator by Economics Times for year 2008 - 2009.

Please get it from here

Note: Only for employed person only

SQL - Difference between CAST,CONVERT and PARSE

TODO---