Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
41 active users
175 visitors today
709 pages today
how is this done?
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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

Tiki Statues - Tiki Masks - Tiki Totems


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


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...


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!


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!