Intranet Journal   Earthweb  
Images Events Jobs Premium Services Media Kit Network Map E-mail Offers Vendor Solutions Webcasts

   Intranet Journal Subjects
Search Earthweb

Privacy Policy



internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

internet commerce
Be a Commerce Partner
















 

[ Home | Discussion Forum | How Do I... | Lotus Notes Intranets | Microsoft SharePoint | Products | Shopping  ]

free news!

Creating An Intranet Site with ASP: Part 1


Peter Zeidman
R&D Consultant (pzman@dsl.pipex.com, http://www.todaynet.co.uk)

Printer Friendly Version

Part 1: Creating the database and reading from it

Firstly, let me outline what this tutorial will do. This is a practical guide, which will show you how to put together an intranet system, using ASP. This system will be easy to use for the complete novice, and simple to administer. This guide provides a basic outline: you will have to customize it to your needs.

That said, let's get going. These are the main features of our system:

  • An interface for the user to select and read articles in categories and sub-categories, e.g. 'marketing' as a category and 'news' as its sub-category.
  • A control panel for the staff to use, with no programming knowledge, to update their department's Intranet site.
  • A central control panel for the administrator to use, to over see the workings of the site.

For this tutorial, I assume that you're using Microsoft Internet Information Server or Microsoft Personal Webserver. If you're an NT user and you don't have IIS, then you can download it from microsoft.com as part of the NT Option Pack.

I promised a practical guide, so let's get practical.

Step 1: Putting the database together

All of the information on the Intranet site, such as articles, will be stored in a database. This will provide a central location for information, making the site easier to back-up and organize. Consider your needs for the database. Below is a sample table:

| ID | Title | Author | Department | Date | Body |Enabled |

And here are the values for one article:

| 01 | Request | Peter | HR | 03/07/2001 | Give me money!! | Yes |

So, the 'ID' column contains a unique reference number, and 'title', 'author' and 'department' are text values. 'Date' obviously contains the date, 'body' contains the article and 'enabled' lets the administrator enable or disable a particular article.

Draw out the columns you need for your site, and using software such as Microsoft Access, create a database. There should be a main table, which must contain the field entitled 'ID'. See below:

'ID': Set to 'autoincrement', 'long', 'unique', and 'primary key'.

For the other Fields:

Text values: Anything needing text values under 200 characters, set the datatype to 'text'.
Long text values: For text longer than 200 characters, set to the 'memo' data type.
Numbers: Use the 'integer' type for short numbers, 'long' for longer numbers.

Add a sample record using Access, like I've done above, and save your database in MDB format. Put this in a folder called 'databases' within the folder used by your web server, usually called WWWroot or Inetpub.

Step 2: The Interface: Creating a page to list all records in the database

The first step of the interface will be to to read articles from the database, and show them to the user. The code below will do this, and is fully annotated. NOTE: I advise you understand how this code works before you use it, by reading the accompanying notes, in case anything goes wrong. If you don't understand it all, don't panic!


<%
'The first line declares the variables

Dim dblocat, cnn, cnnstring, rs, SQL

'The location of our database is stored in the variable called dblocat
'Change it to the location of your database on the server.
dblocat = "c:\inetpub\tutorial\data\intranet.mdb"

'These 2 lines tell the server how to connect to the database.
'cnn is used to store the 'connection object', ie how to connect to the database
'cnnstring stores the method in which the database is connected to, and takes
'dblocat (above) as the location for the database.

set cnn = server.CreateObject("ADODB.Connection")
cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dblocat

'Now we've told it how to connect, this says to the server "Go Connect!"

cnn.open(cnnstring)

'Right, we're doing well. The database is open, ready and waiting. Now, let's
'get some data out of it. These 2 lines create a 'recordset', basically letting
'you read the database.

Set rs = server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cnn

'Now we can query the database. The following line will do this:

SQL= "SELECT * From departmental"

'The stament above should be written in the format: 'SELECT * From tablename'
'Where 'tablename' is the name of the table you created earlier in the database.

rs.Open SQL

'Now, print the results on the screen. The HTML Tags, below, will put the data into a simple table.

rs.MoveFirst
%>
<table border="0" cellspacing="0" cellpadding="0" align="center" width="80%">
<tr> <td><b>Title</b></td> <td><b>Author</b></td> <td><b>Date</b></td> </tr>
<tr><td></td><td></td><td></td></tr>

<%
while not rs.EOF ' Keep going until all of the records have been displayed.
%>
<tr><td><%=rs("Title")%></td> <td><%=rs("Author")%></td>
<td><%=rs("Date")%></td>

<%
'Now, move to the next record & start again.
rs.MoveNext
wend

%>
<%

'Now, close the table & end the connection to the database.
Response.Write("</table></font>")
rs.close
cnn.close
%>

And you're done! This page will produce the following table:

As you can see, I added 3 sample records to the database, which were listed in turn.

With regards to how things were kept in tabular form, typing <tr> will start a new row and </tr> will end it. Everything in between these two "tags" goes in that row. Typing <td> will start a cell within a row, and </td> will close it. Using these four tags, you can create a table with multiple rows and columns. For more information, get a book on HTML or download and examine the code example at the bottom of the page.

Using this code, you can keep a central source of information that any page can read from. However, this displays all of the records; what you really want is to be selective with what you show. That will be covered in the next tutorial.

 

Download the code and database:

Lesson1.asp (todo: edit the line specifying the database path (line 8) )

Intranet.mdb (todo: Put it in a sub-folder called data underneath the ASP file)

Next time:

  • Choosing which data is shown.
  • Creating a search engine.

Further reading:

  • HTML For Dummies
  • ASP By Example

Printer Friendly Version

Of Interest
· Intranet eXchange Discussion Board

· Advice and Opinions

email this page

Tutorials
and more at:
Intranet Journal's Tutorials
Intranet Journal Favorites

Creating a PHP-Based Content Management System

The Spyware Guide

Introduction to Microsoft SharePoint Portal

Intranet Journal
Part of the EarthWeb Network

Managing Editor
Intranet Journal

Tom Dunlap

EarthWeb Home Page
Jupitermedia Home Page

Media Kit





JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES