ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Get the News --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
156 active users
3128 visitors today
4692 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

The ASP file we're going to generate is shown below - I will #include it just like any other file, then call the function ShowNews().

utils/News.asp

<%
function ShowNews ( )
{
   Out('<table width="100%" border="0" align="center">' );
   Out('<tr><td width="90%" nowrap valign="top">' );
   Out('<table width="100%">');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6275" target="CYAExternal">Amazing New ASP Template Pack</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6274" target="CYAExternal">A/V Publisher</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6273" target="CYAExternal">fXgraph Ver 4 Beta Animated Graphing Comp Released</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6271" target="CYAExternal">CompareFilesX now has reporting built in</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6272" target="CYAExternal">CodeCharge Studio ASP code generator Released</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6298" target="CYAExternal">URLDecode Function</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6297" target="CYAExternal">An Extensive Examination of the DataGrid Web Control: Part 5</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6296" target="CYAExternal">Protecting Portions of your Web Site</a></td></tr>');
   Out('<tr><td>&#149;&nbsp;<a href="http://aspwire.com/brief.asp?6295" target="CYAExternal">Specifying Configuration Settings in Web.config</a></td></tr>');
   Out('</table>');
Out('</td><td width="10%" nowrap valign="bottom">' );
Out('<a href="http://aspwire.com/" target="CYAExternal"><img src="images/Affiliates/ASPWire.gif" width="100" height="30" alt="News from ASPWire" border="0"></a><br><b>Powered by ASPWire</b><br><a href="GetNews.asp">Read how this is done</a>');
Out ( '</td></tr></table>' );
}
%>
Back in OnInitialUpdate, here's how I created the News.asp file:

// open file to store formatted data into
TCHAR* sNewsFile = _T( "News.asp" );
CStdioFile cfASP ( sNewsFile, CFile::modeCreate | CFile::modeWrite );

// output the static part of the asp file - the function declaration,
// the ASPWire image and the heading
cfASP.WriteString ( _T("<%\nfunction ShowNews ( )\n{\n") );
cfASP.WriteString ( _T("\tOut('<a href=\"http://aspwire.com/\"><img src=\"images/ASPWireNews.gif\" alt=\"News from ASPWire\" border=0></a>');\n") );
cfASP.WriteString ( _T("\tOut('&nbsp;&nbsp;&nbsp;(<a href=\"GetNews.asp\">Read how this is done</a>)<p>');\n") );
cfASP.WriteString ( _T("\tOut('<table width=\"100%\">');\n") );

cfRaw.SeekToBegin ();

CString sLine;
bool bNewRow = true;

for (int i=0; ; i++)
{
   if ( FALSE == cfRaw.ReadString ( sLine ) )
      break;

   switch ( i % 4 )
   {
   case 0:      // URL
      cfASP.WriteString ( _T("\tOut('") );

      if ( bNewRow )
         cfASP.WriteString ( _T ( "<tr>" ) );

      bNewRow = !bNewRow;

      cfASP.WriteString ( _T("<td>&#149;&nbsp;<a href=\"") );
      cfASP.WriteString ( sLine );
      cfASP.WriteString ( _T("\" target=\"CYAExternal\">") );
      break;

   case 3:      // title
      sLine.Replace ( "'", "\\'" );
      cfASP.WriteString ( sLine );
      cfASP.WriteString ( _T("</a></td>") );

      if ( bNewRow )
         cfASP.WriteString ( _T ( "</tr>" ) );

      cfASP.WriteString ( _T("');\n") );
      break;
   }
}

cfASP.WriteString ( _T("\tOut('</table>');\n") );
cfASP.WriteString ( _T("}\n%>") );


// close files
cfRaw.Close ();
cfASP.Close ();

As Emeril would say: BAM! Now I have our News.asp file on our local machine, so the last step is to upload it to our server.

Part 4: Uploading via FTP...

Featured sponsor
My favorite resources

Selling products online - read how James does it now



New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!