unit5(serverside web programming in asp technology)

Upload: anjuch

Post on 30-May-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    1/24

    What is common Gateway Interface

    The Common Gateway Interface (CGI) is a specification defined by the World WideWeb Consortium (W3C), defining how a program interacts with a Hyper Text Transfer

    Protocol (HTTP) Server. The Common Gateway Interface (CGI) provides the

    middleware between WWW servers and external databases and information sources.

    Why is CGI Used?

    An interesting aspect of a CGI enables Web server is that computer programs can be

    created and deployed that can accept user input and create a Web page on the fly.

    Interactive web pates enable a client to send information to the Web server and get back a

    response that depends on the input.

    The sequence of events for creating a dynamic HTML document on the fly through CGIscripting is as follows:

    A client makes an HTTP request by means of a URL. This URL could be typed

    into the Location window of a browser, be hyperlink or be specified in theAction attribute of an HTML tag.

    From the URL, the Web server determines that it should activate the gateway

    program listed in the URL and send any parameters passed via the URL to that

    program.

    The gateway program processes the information and returns HTML text to the

    Web server. The server, in turn, adds a MIME header and returns the HTML text

    to the Web browser. The Web browser displays the document received from the Web Server.

    How information is transferred from the Web Browser to a CGI program

    GET:

    The Web browser submits the forms data as a part of a URL.

    POST:

    HTTP

    Web Browser WebServer

    CGI

    CGI Program

    Database

    Disk Files

    sua as c sua

    ASP Other

    ADO

    ServiceComponentsCursor Engine Query Processor

    Data Providers

    ODBC OLE DBSimple Data

    Main frame

    data

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    2/24

    The web browser sends the forms data separately from the URL as a stream of

    bits.

    How a CGI URL is interpreted by the Web Server

    The Web Server must be configured to recognize an HTTP request for a CGI program.

    The URL specifying a CGI program looks like any other URL, but the Web Server can

    examine the directory name and determine whether the URL is a normal document or aCGI program.

    The Web server expects the CGI programs name to appear immediately following the

    CGI directory (e.g. /cgi-bin/)The Web Server must be configured to recognize an HTTP request for a CGI program.

    The URL specifying a CGI program looks like any other URL, but the Web Server can

    examine the directory name and determine whether the URL is a normal document or a

    CGI program.

    The Web server expects the CGI programs name to appear immediately following theCGI directory (e.g. /cgi-bin/).

    Programming Languages

    CGI programs have been developed in C, C++, Visual Basic Script (VB Script), Perl,

    TCL, REXX, Python, Icon, AppleScript, Unix shell script, JavaScript, Java Server

    Pages(JSP), Active Server Pages(ASP) and even Dos Batch files.

    Active Server Pages

    Static Contents

    HTML was used to display linked static contents. It involved manually changing the

    contents of HTML pages to customize it for different types of browsers. The serverreceived the request and sent the HTML document file. The browser then displayed the

    document in the requested format. The interaction was limited to the user who was using

    a browser and the Web Server. Web pages could not be made to interact with a user, andthey could not show dynamic content.

    Dynamic Web pages

    The systems used earlier involved custom servers delivering particular types of dynamic

    content. With the development of Web servers, the need for displaying data dynamicallyand also in a customized way arose. Client scripts are processed on the client side.

    web server is able to process the requests of clients quickly since it does not not have the

    overhead of processing script of the requested file.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    3/24

    Need for Sever-Side Scripting

    The need for server-side scripting comes from the need for active web sites, using

    information from the databases and customizing the content of the Web pages for each

    user.

    Benefits of server-side scripting are:

    Server-side scripting enables web applications to access database.

    Server-side scripting allows the use of templates for creating HTML documents, in

    which the contents of the pages can be retrieved from databases, text files, and other data

    sources.Server-side scripting also enables us to develop Web applications such that changing the

    HTML design does not affect the programs that retrieve data from databases.

    Optimizing the Creation of Dynamic Web pages

    The optimal Web page combines server-side and client-side scripting. The general rules

    for using client-side and server-side scripting are:

    Any access to the data that resides on the client, such as the time or the type of browserused, should be implemented with client-side scripting.

    Any access to data that resides anywhere except the client should be implemented with

    server-side scripting.Minor changes to the HTML layout and properties should be managed on the client side.

    Major differences in the HTML or media that a client will receive should be managed on

    the server side.

    Active Server pages

    Microsoft Active Server pages (ASP) was developed by Microsoft on July 16,1996, as a

    powerful and easy technology to create dynamic web pages.

    The main purpose of ASP is to decrease the load on the browser by performing many of

    the tasks done earlier by the browser, thus increasing the response time for each request.Using ASP, you can combine HTML pages, script commands, and ActiveX components

    to create interactive Web pages.

    ASP can be used with the following Web servers

    Microsoft Internet Information Server version 3.0 on Windows NT Server 4.0, Windows2000 server

    Microsoft Peer Web Services version 3.0 on Windows NT Workstation 4.0, windows

    2000 professional

    Microsoft Personal Web Server on Windows 95/98

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    4/24

    How an ASP file Executes

    ]

    The client, a browser, sends a request for an ASP file.

    The Web server, or the IIS server, receives the request and retrieves the ASP file from

    the disk or memory.

    The Web server forwards the ASP file to a script engine, ASP.dll, for processing.The ASP file is read and interpreted from top to bottom and the commands in the delimiters are executed.

    The processed ASP file is generated as an HTML document and the contents are sentback to the client.

    The client interprets the output and display it.

    ASP coding

    Output in

    HTMLformat

    Client

    Request

    Client receives only the HTMLthat was generated fromthe script.

    All ASP commands and variables are resolved beforebeingsent to the client

    BrowserWeb Server

    Active Server Pages

    HTTP Request

    HTTP Response

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    5/24

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    6/24

    Session: This object used for storing user information that is needed for a particular

    client session.

    Request: This is used to determine information about specific client request such aswhether it was GET or a POST and the cookies passed in the header.

    Response: This object is used to customize the response written from the server to the

    client.ObjectContext: You can use ObjectContext object to either commit or abort a

    transaction initiated by a script in an ASP. The transaction is managed by Microsoft

    Transaction Server(MTS).

    Server Object

    The ASP Server object can store user-defined variables, and also contain variables

    whose values are tied directly to the server itself

    The variables stored in the Server object are common to all the Web pages on the Web

    server.This enables the value to the same for all the users on all the pages.

    Server Properties

    ScriptTimeout: property set the time limit for which a script will be allowed to process arequest.

    Method

    URLEncode

    Server.URLEncode(
    The proper way to write)

    HTMLEncode

    Server.HTMLEncode("
    The proper way to write ")

    MapPath: The MapPath method converts the name of a Web directory to the actualdirectory path on the Server.

    C:\inetpub\

    C:\inetpub\aspscripts\test\Server.MapPath(/sample.txt)

    C:\inetpub\sample.txt

    Server.MapPath(sample.txt)C:\inetpub\aspscripts\test\sample.txt

    CreateObject: method is ued to create an instance of a component. The ASP built-in

    objects cannot be directly instantiated; the web server handles their instantiation itself.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    7/24

    After an object is initialized, its methods and properties are accessed using the same

    syntax as that used for built-in objects.

    Request Object

    It requires to collect information from a user.

    The Request object consists of various properties, methods, and collections.

    Syntax

    Request[.collection|property|method](variable)

    Collection

    Form: This is used to retrieve the values of the form elements in the HTTP request bodyRequest.form(element)[(index)|.Count]

    Cookies: This is used to retrieve the values in the cookies sent in an HTTP request.Request.Cookies(cookie)[(key)|.attribute]

    QueryString: This is used to retrieve the values of variables in the HTTP query string.

    Request.QueryString(variable)[(index)|.Count]ServerVariables: This is used to retrieve the values of predetermined environmental

    variables.

    Request.ServerVariables(server environment variable)

    Property

    TotalBytes: This is a read-only property. It specifies the total number of bytes a client is

    sending in the body of the request.Counter=Request.TotalBytes

    Method

    To retrieve the data sent to the server from the client.

    Variant=Request.BinaryRead(count)

    The two instances when query strings should not be used are:

    When you need to pass hidden dataWhen you are passing a large amount of data.

    ServerVariables Collection

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    8/24

    The ServerVariables collection of the Request objec tis used to retrieve the headers that

    are part of the request sent by the browser to the Web Server.

    The ServerVariables collection contains both headers and additional information aboutthe server.

    The collections, properties, and methods of the Response object are given below:

    CollectionCookies: This is used to set the cookie values

    Response.cookies(cookie)[(key)|.attribute]=value

    Property

    Buffer: This is used to indicate whether the page output is buffered.Response.Buffer [=flag]

    CacheControl: This determines whether the proxy servers are able to cache the outputgenerated by ASP.

    Response.CacheControl[=Cache Control Header]

    Charset: This appends the name of the character set to the content-type header.

    Response.Charset(CharsetName)Content-type: This specifies the HTTP content type for the response.

    Response.ContentType [=ContentType]

    Expires: This specifies the length of time before a page cached on a browser expires.Response.Expires [=number]

    ExpireAbsolute: This specifies the date and time on which a page cached on a browser

    expires.Response.ExpiresAbsolute [=[date] [time]]

    IsClientConnect: This indicates whether the client has disconnected from the server

    Response.isClientConnected()

    Status: This contains the value of the status line returned by the server.

    Response.status=StatusDescription

    Method

    AddHeader: This sets the HTML header name to value

    Response.AddHeader name,value

    AppendToLog: This add a string to the end of the Web server log entry for this request.

    Response.AppendToLog string.BinaryWrite: This writes the given information to the current HTTP output without any

    character-set conversion.

    Clear: This erases any buffered HTML output.

    Response.clear

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    9/24

    End: This stops the processing of the .asp file and return the current result.

    Response.End

    Flush: This sends the buffered output immediately.Response.Flush

    Redirect: This sends a redirect message to the browser causing it to attempt to connect to

    a different URL.Response.Redirect URL

    Write: This writes a variable to the current HTTP output as a string.

    Response.Write variant

    Buffering the Output

    When an Active Server Page is requested, the server processes the page As each line of

    the page is being processed, the output is sent to the browser. It creates a cascading effect

    of the output because it is displayed one line a time.

    Buffered Output

    Caching the Output

    The output is cached to improve system performance in terms of the speed of retrieval ofWeb pages.

    If the page is stored in the cache of the browser, every time it is requested for, it can be

    displayed from cache.

    The Response object properties, Expires, ExpireAbsolute and CacheControl, can be usedfor controlling the caching of pages.

    Redirect

    This sends a redirect message to the browser causing it to attempt to connect to a

    different URL.Syntax: Response.write URL

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    10/24

    Data Access Techonology

    Web applications used to store a part of the data for future use.The data can be stored in databases, electronic spreadsheets, or even text files.

    To access the data that is stored in databases, there are various methods. The main data

    access techniques are listed below:

    MDAC-Microsoft Data Access Components (MDAC), contains all the softwarecomponents of Microsoft for database access.

    ADO-ActiveX Data Objects (ADO) provides an object-oriented programming interface

    for accessing data sources such as Mircrosoft SQL Server and Microsoft Access. You can

    use ADO directly in ASP to access data sources.ADOX- ADO Extensions (ADOX) for DLL and security is a a collection of objects that

    helps to manage database objects.RDS- Resource Data Service (RDS) is collection of objects that enables us to

    communicate with data sources that located remotely.

    OLE DB- OLE DB is a system-level interface to data providers. ADO uses the set of

    interfaces provided by OLE DB to communicate with data sources.ODBC- Open Database Connectivity (ODBC) is a standard developed by Microsoft to

    simplify the development of applications that need to be independent of database

    platforms. ODBC is implemented through a collection of database drivers that areprovided by Microsoft and third party vendors. ODBC database drivers contain driver

    libraries that provide an application with the functionality to utilize a variety of database

    formats.

    Universal Data Access Architecture

    Microsoft Data Access Components (MDAC) is the practical implementation of the

    UDA architecture.

    Universal Data Access is a platform for developing enterprise-wide applications thatneed access to various relational and non-relational data sources across a network.

    UDA architecture consists of three parts: data consumers, services components, and data

    providers.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    11/24

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    12/24

    Parameters Collection: is used to pass specific data to a parameterized query or the

    stored procedures in a SQL database.

    Fields Collection: The fields Collection is used to to access specific fields in an existingRecordset object.

    Connecting to Microsoft SQL server

    Or

    Connecting to a Mircrosoft Access DatabaseInserting Records into a Database table

    Closing a SQL Connection

    Command Object

    The command object represents a command, that is, a SQL statement that can execute

    against any data source. The command object is optional in an ADO model because some

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    13/24

    data providers cannot supply command execution, but the object is supported if the

    provider supports the commands

    A command object requires a Connection object. The data returned on the execution ofcommand is accepted and stored in a Recordset object.

    PropertyActiveConnection

    CommanText

    CommandTypePrepared

    State

    Name

    Method

    Execute: execute the SQL statement or stored procedures specified in the CommandText

    propertyCancel: Cancels the currently executing command

    CreateParameter: creates a new Parameter object with the specified properties.

    Set myConnection=Server.CreateObject(ADODB.Connection)

    myConnection.open provider=sqloledb; data source=school; uid=sa; pwd=admin;

    database=schoolSet myCommand=Server.CreateObject(ADODB.Command)

    myCommand.ActiveConnection=myConnecton

    myCommand.CommandText=select * from studentSet myRecordset = myCommand.Execute

    Recordset Object

    ADO recordsets are used to display records that are retrieved from a database table in an

    Active Server Page.Some of the properties of the Recordset object are given below:

    AbsolutePage

    AbsolutePosition

    ActiveConnectionBOF

    Eof

    BookmarkCachesize

    CursorType

    EditModeLockType

    MaxRecords

    PageCount

    PageSize

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    14/24

    RecordCount

    Source

    StatusMarshallOption

    CursorLocation

    Filter

    Methods

    AddNew

    CancelBatch

    CloneDelete

    GetRows

    Move

    MoveFirstMoveLast

    MoveNextMovePrevious

    NextRecordSet

    OpenRequery

    Resync

    SupportsUpdate

    UpdataBatch

    Close

    Creating a Recordset Object

    A Recordset object need not be created explicitly. The Recordset object is returned

    automatically by the Connection object when the SQL Query is executed.

    SyntaxSet recordset object=.execute

    Creating RecordSets

    RecordSet.Open [source],[activeConnection],[cursortype],[locktype],[options]

    Different types of Recordsets in ADO

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    15/24

    Static cursor: It provides a static copy of the set of records for us to find data or

    gernerate reports. Additions, changes, or deletions by other users are not visible.

    Dynamic Cursor: It allows changes to the view due to the additions, changes, anddeletions by other users.

    Keyset-driven Cursor: It functions line a dynamic cursor, except that it prevents us from

    viewing the records that other users add and prevents access to the records that othersusers delete.

    Forward-only Cursor: It functions identically to a static cursor, except that it only allows

    us to scroll forward through the records.Default cursor type is forward-key cursor while opening the recordset without specifying

    the recordset type.

    Value that assigned to the CursorType property

    adOpenForwardOnly 0 Forward-only

    adOpenkeyset 1 Keyset-driven

    adOpenDynamic 2 DynamicadOpenStatic 3 Static

    Locking Records

    In a multi-user environment, more than one user can simultaneously access a recordsetresiding on the server. When more than user requires to update a record in a database

    table, it can lead to conflicts.

    This called the problem of cocurrency.Such problems can be avoided by locking the Recordset object.

    The LockType property of the RecordSet object determines the type of lock placed onthe data of the associated database during editing.

    LockType

    adLockUnspecfied -1 does not specify the lockadLockReadOnly 1

    adLockPessimistic 2

    adLockOptimistic 3

    adLockBatchOptimistic 4

    Fields Collection

    This Fields collection contains a Field object for each field(column) in the recordset.

    The fields collection is the default collection of the recordset, and can therefore beomitted when accessing fields

    rsAuthors.Fields(au_lname).value

    rsAuthors(au_lname).value

    rsAuthors(1).value

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    16/24

    rsAuthors.Fields(1).value

    For each fldAuthor in rsAuthors.Fieldsresponse.write fldAuthor.Name & : & fldAuthor.value &

    Next

    For I=0 to rsAuthors.fields.count-1response.write rsAuthors.Fields(I).value

    next

    Filtering RecordSets

    Filtering is a way of temporarily restricting the view of records in a recordset.

    It only shows certain records in a recordset on condition

    If you dont want to re-query the data store every time, filter can be used.

    rsAuthors.Filter=fname=tinarsAuthors.Filter=fname=tina or lname=Thapa

    rsAuthors.Filter=fname like j%rsAuthors.Filter= reset or clear the filter

    Searching for Records

    Searching for individual records is performed with the Find method.

    rsAuthors.Find fname=jaiThe main difference between search and filter is that you can only have one criterion-

    using And or Not is not allowed.

    Recordset.find Criteria, [skiprows],[searchdirection],[start]Skiprows- is a number, indicating the number of rows to skip before starting the search.

    By default this is 0, and the search starts on the current row

    SearchDirection can be either adSearchForward to search forwards in the recordset, oradSearchBackward to search backwards in the recordset.

    Stat is a bookmark, identifying the position from which start the search.

    Location of Recordsets

    ASP-based

    Application

    Client Side

    DatabaseData Request

    Data Response

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    17/24

    In an ASP-based application, whenever a recordset is created, it is, by default, created as

    server-side cursor.

    ASP allows client-and server-side cursors. A cursor that is used on the server-side is

    opened and managed by the machine that has the database.When a client-side cursor is used, it is opened and managed by the machine hosting the

    Active Server Page.

    SyntaxRecordsetObject.CursorLocation=locationType

    adUseNone: The recordset does not support cursors. This is to enable backward-

    compatibility with databases that do not have a cursor object.

    adUseClient: The recordset is created on the client machine

    asUseServer: The recordset is created on the server machine.

    What is an ASP Applications?

    An ASP application can be defined as a set of inter-related Active Server Pages.

    In ASP, each virtual directory on a Web Server is an application, and all the files and

    folders in that virtual directory form a part of the application.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    18/24

    Properties of an ASP Application

    It allows the sharing of data among the pages in the application.

    It triggers various application scripts based on an event. For example, the start of anapplication is an event.

    It allows the instances of objects to be shared among all the pages of an application.

    A web site can have different applications, each having individual properties.When an application ends, it does not affect the other applications.

    Each application can be run in its own memory space, resulting in more security fo

    information.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    19/24

    An Application Object

    An application object is used to store the information that is common to an ASP

    application and is shared by all the users of the application.ASP applications are used to retain information that may be used by other web pages.

    This is also called maintaining the state in ASP.

    Maintaining state

    ASP applications are used to retain information that may be used by other web pages.

    This is also called maintaining state in ASP.An ASP application maintains two types states:

    The application state retains the information of the application that is available to all the

    users of the application.

    The session state retains the information that is required by a specific user in a session. Asession starts when a user requests for a page from a web site and ends when the

    user leaves the web site.

    Application ObjectAn Application object is used to initialize an application, automatically start processes

    that are required for an application, and allow the declaration of variables that canbe used by all the users and across all the pages.

    Application Object Methods

    Lock: it prevents other clients from modifying the properties of the Application object.Application.Lock

    Unlock: it allows the clients to modify the properties of the Application object.

    Application.Unlock

    Application object Events

    Application_onStart: it marks the beginning of an Application event.Application_OnEnd: it marks the end of an application event.

    Controlling the Start and End of an Application Using the Global.asa file

    The Global.asa file resides in the same folder as the application. An application generates

    certain events such as when it starts for the first time or when it ends.

    Global.asa file contains scripts for the start and end events of an application or a session.

    Each application can have only one global.asa file attached to it.

    Sub application_onStartApplication.lock

    Application(custname)=Jennie

    Application.unlockEnd sub

    Sub Application_onEnd

    ..

    End sub

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    20/24

    Application Variables

    Application variable is used to store data that can be accessed throughout all the pages of

    the application and by all the users of the application.

    An application can contain any type of data, including arrays and objects.

    Some of the purposes of application variables are to:

    Display momentary information on every web page, for example, to display the daily

    news updates

    Count the number of times a user has accessed the site

    Hold the data retrieved from the database and display the details on multiple web pagesEnable communication among users, for example, to create applications that help users to

    chat.

    Session ObjectThe session object is used to store the information required for a particular session by a

    specific user.The variables stored in the Session object are available to users throughout the

    application for a particular session.

    The web server automatically creates a Session object for a user who requests for a page

    of an application if the user does not already have a session.The web server destroys the Session object when the session is terminated or timed out.

    A Session Object Method

    Abandon: it prevents other clients from modifying the Application object properties

    Session.Abandon

    A Session Object Property

    TimeOut: it has the timeout period for the session state of the current application, inminutes.

    Session.TimeOut=minutes

    SessionID: it returns the session ID for the user of the current session.

    Session.SessionID

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    21/24

    File Handling in ASP

    The Scripting.FileSystemObject Object

    The FileSystemObject object provides access to the computers file system, allowing us

    to manipulate text files, folders and drives from within our code.

    It is one of the objects provided by the Scripting Runtime Library, and is available inVBScript and Jscript for use in ASP pages on the Server.

    It can also be used client-side in IE 5, providing that the pages have the .hta file extension

    to indicate that they are part of a Hypertext Application (HTA).

    The FileSystemObjects Property

    The FileSystemObject object has a single property that allows us to retrieve a list of all

    the valid drives on the current machine:Drives: Returns a collection of Drive objects that are available from the local machine.

    This includes network drives that are mapped from this machine.

    The FileSystemObjects MethodsThe FileSysemObject object provides a range of methods for manipulating the subsidiary

    objects like Drive, Folder and File.It implements two methods for working with TextStream objects: CreateTextFile and

    OpenTextFile.

    The FileSystemObjects methods are divided into three categories depending on the type

    of the object that each is designed to work with.Methods for working with Drives

    Methods for working with Folders

    Methods for working with Files

    Methods for working with Drives

    DriveExists(drivespec): Returns True if the drive specified in drivespec exists, or False ifnot. The drivespec parameter can be a drive letter as a string or a full absolute path

    for a folder or file.

    DriveExists(c) DriveExists(c:) DriveExists(c:\)

    GetDrive (drivespec)

    GetDriveName(drivespec)

    copyFolder(source,destination,overwrite)CreateFolder(foldername)

    DeleteFolder(folderspec,force): if the optionalforceparameter is set to True, the folders

    will be deleted even if their read-only attribute (or that of any contained files) is set.The default forforce is False.

    FolderExists (folderspec): Returns True if the folder specified infolderspec exists, or

    False is not.GetFolder (folderspec): Returns a Folder object corresponding to the folder specified in

    folderspec.

    GetParentFoldrName (pathspec): Returns the name of the parent folder of the file or

    folder specified inpathsepc. Does not check for existence of the folder.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    22/24

    MoveFolder(source,destination)

    Methods for working with Files

    Copyfile(source,destination,overwrite)

    CreateTextFile (filename, overwrite,unicode): overwrite is True any existing file with the

    same path and name will be ovewritten. The Default for overwrite is False. If theoptional unicode parameter set to True, the content of the file will be stored as

    Unicode text. The default for unicode is False.

    DeleteFile(filespec,force): if the optionalforce parameter is set to True, the file(s) will bedeleted even if the Read-only attributes is set. The default forforce is False.

    FileExists(fiespec): Returns True if the file specified in filespec exists, or False if not.

    GetFile(filespec): Returns a File object corresponding to the file specified in fiespec.

    GetFileName(pathspec): Returns the name part of the path and filename specified in

    filespec.

    MoveFile(source,destination): Moves the file or files specified in source to the folder

    specified in destination. Wildcards can be included in source but not in destination.OpenTextFile(filename,iomode,create,format): Create a file named filename, or opens an

    existing file named filename, and returns a TextStream object that refers to it.(contd..)

    The iomode parameter specifies the type of access required. The permissible values are

    ForReading(1 the default), ForWriting(2), and ForAppending(8).If create parameter is set to True when writing or appending to a file that does not exist, a

    new file will be created. The default for create is False.

    Theformatparameter specifies the format of the data to be read from or written to thefile. Permissible values are TristateFalse(0-default) open it as ASCII,

    TristateTrue(1) to open it as Unicode, and TriStateDefault(2) to open it using the

    system default format.

    The Drive Object

    FileSystemObject object contains one property-Drives-which returns a collectionconsisting of all Drive objects available on the local machine.

    The Drive object exposes these properties:

    AvailableSpace: Returns the amount of space available to this user on the drive, taking

    into account and/or other restrictions.DriveLetter: Returns the drive letter of the drive.

    DriveType: Returns the type of the drive. The values are Unknown(0), Removable(1),

    Fixed(2), Network(3), CDRom(4), and RamDisk(5).FileSystem: Returns the type of file system for the drive. The values include FAT,

    NTFS and CDFS.

    FreeSpace: Returns the actual total amount of free space available on the drive.

    IsReady: Returns a Boolean value indicating if the drive is ready(true) or not (False).

    Path: Returns the path for the drive as a drive letter and colon, I.e. C:

    RootFolder: Returns a Folder object representing the root folder of the drive.

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    23/24

    SerialNumber: Returns a decimal serial number used to uniquely identify a disk volume.

    ShareName: Returns the network share name for the drive if it is a networked drive.

    TotalSize: Returns the total size (in bytes) of the drive.VolumeName: sets or returns the volume name of the drive if it is a local drive.

    The Folder ObjectThe RootFolder property of the Drive object returns a Folder object, through which we

    can access all of the content of this drive. We can use the properties and methods of

    the folder object to traverse directories on the drive, and to get at all the propertiesof this or any folder.

    The Folder Objects Properties

    The folder object provides a set of properties that we can use to get more informationabout current folder, and to change the folder name:

    Attributes: Returns the attributes of the folder. Can be a combination of any of the

    following values: Normal(0), ReadOnly(1), Hidden(2), System(4), Volume(Name)

    (8), Directory(folder)(16), Archive(32), Alias(64), Compressed(128).

    DateCreated: Returns the date and time that the folder was created.DateLastAccessed: Returns the date and time that the folder was last accessed.

    DateLastModified: Returns the date and time that the folder was last modified.

    Drive: Returns the drive letter of the drive on which the folder resides.

    Files: Returns a Files collection containing File objects representing all the files withinthis folder.

    IsRootFolder: Returns a Boolean value indicating if the folder is the root folder of the

    current drive.Name: Sets or returns the name of the folder.

    ParentFolder: Returns the Folder object for the parent folder of this folder.

    Path: Returns the absolute path of the folder, using long file names where appropriate.

    ShortName: Returns the Dos-style 8.3 version of the folder name.

    ShortPath: Returns the DOS-style 8.3 version of the absolute path of this folder.Size: Returns the size of all files and subfolders contained in the folder.

    SubFolders: Returns a Folders collection consisting of all folders contained in the folder,

    including hidden and system folders.

    Type: Returns a string that is a description of the folder type (such as Recycle Bin) ifavailable.

    The Folder Objects Methods

    The Folder object provides a set of methods that can be used to copy, delete and move the

    current folder. The work in the same way as the CopyFolder, DeleteFolder and

    MoveFolder methods of the FileSystemObject object, but dont require a sourceparameter because the source is this folder.

    Copy (destination,overwrite)

    Delete (force)

  • 8/14/2019 Unit5(ServerSide Web Programming in ASP Technology)

    24/24

    Move()

    CreateTextFile(filename,overwrite,unicode)

    The File Object

    The File object provides access to the properties of a file, and implements methods that

    we can use to manipulate the at file.The File Objects PropertiesThe file object has series of properties that are similar to the Folder object:

    Attributes: Returns the attributes of the file. Can be a combination of any of thefollowing values: Normal(0), ReadOnly(1), Hidden(2), System(4), Volume(Name)

    (8), Directory(folder)(16), Archive(32), Alias(64) and Compressed(128).

    DateCreated: Returns the date and time that the file was created.

    DateLastAccessed: Returns the date and time that the file was last accessed.DateLastModified: Returns the date and time that the file was last modified.

    Drive: Returns a drive object representing the drive on which the file resides.

    Name: Sets or returns the name of the file.

    ParentFolder: Returns the Folder object for the parent folder of this file.

    Path: Returns the absolute path of the file, using long file names where appropriate.Shortname: Returns the DOS-style 8.3 version of the file name.

    ShortPath: Returns the DOS-style 8.3 version of the absolute path of this file.

    Size: Returns the size of the file in bytes

    Type: Returns a string that is description of the file type (such as Text Document fora .txt file) if available.

    The File Objects Methods

    The methods of the File object allow us to copy, delete and move the file. Theres also amethod hat we use to open the file as text stream:

    Copy(destination, overwrite)

    Delete(force)Move()

    CreateTextFile(filename,overwrite,unicode)

    OpenAsTextStream(unicode,format)