<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kristof Neirynck &#187; asp</title>
	<atom:link href="http://www.crydust.be/blog/category/asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crydust.be/blog</link>
	<description>yet another webdev blog</description>
	<lastBuildDate>Sat, 11 Jun 2011 15:57:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>IE8 aggressive caching fix</title>
		<link>http://www.crydust.be/blog/2009/03/20/ie8-aggressive-caching-fix/</link>
		<comments>http://www.crydust.be/blog/2009/03/20/ie8-aggressive-caching-fix/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 10:08:42 +0000</pubDate>
		<dc:creator>Kristof Neirynck</dc:creator>
				<category><![CDATA[asp]]></category>

		<guid isPermaLink="false">http://www.crydust.be/blog/?p=93</guid>
		<description><![CDATA[Apparently Internet Explorer 8 has a more aggressive caching mechanism than any other browser I&#8217;ve ever met. To fix it I&#8217;ve added the following to almost every dynamic page on my server. &#60;% // prevent caching (asp classic jscript) Response.CacheControl = &#34;no-cache&#34;; Response.AddHeader(&#34;Pragma&#34;, &#34;no-cache&#34;); Response.Expires = -1; %&#62; &#60;% ' prevent caching (asp classic vbscript) [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently Internet Explorer 8 has a more aggressive caching mechanism than any other browser I&#8217;ve ever met. To fix it I&#8217;ve added the following to almost every dynamic page on my server.</p>

<pre class="prettyprint">
&lt;%
// prevent caching (asp classic jscript)
Response.CacheControl = &quot;no-cache&quot;;
Response.AddHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);
Response.Expires = -1;
%&gt;
</pre>

<pre class="prettyprint">
&lt;%
' prevent caching (asp classic vbscript) '
Response.CacheControl = &quot;no-cache&quot;
Response.AddHeader &quot;Pragma&quot;, &quot;no-cache&quot;
Response.Expires = -1
%&gt;
</pre>

<pre class="prettyprint">
&lt;?php
// prevent caching (php)
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
?&gt;
</pre>

<pre class="prettyprint">
// prevent caching (C#)
//Response.AddHeader(&quot;Cache-Control&quot;, &quot;no-cache&quot;);
//Response.AddHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);
//Response.Expires = -1;

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);
</pre>

<p>More information here: <a href="http://support.microsoft.com/kb/234067">How to prevent caching in Internet Explorer</a></p>


]]></content:encoded>
			<wfw:commentRss>http://www.crydust.be/blog/2009/03/20/ie8-aggressive-caching-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Excel files in ASP Classic</title>
		<link>http://www.crydust.be/blog/2009/03/02/generate-excel-files-in-asp-classic/</link>
		<comments>http://www.crydust.be/blog/2009/03/02/generate-excel-files-in-asp-classic/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 20:14:40 +0000</pubDate>
		<dc:creator>Kristof Neirynck</dc:creator>
				<category><![CDATA[asp]]></category>

		<guid isPermaLink="false">http://www.crydust.be/blog/?p=78</guid>
		<description><![CDATA[<p>Generating Excel files in ASP Classic is not as easy as I thought. I hope someone finds use in this little piece of code that shows a way to export data to csv and to xls.</p>]]></description>
			<content:encoded><![CDATA[<p>Generating Excel files in ASP Classic is not as easy as I thought. I hope someone finds use in this little piece of code that shows a way to export data to csv and to xls.</p>

<span id="more-78"></span>

<pre class="prettyprint">
&lt;%@LANGUAGE=&quot;JAVASCRIPT&quot; CODEPAGE=&quot;65001&quot;%&gt;
&lt;%

function getData(connectionString, sql){
    var result = null;
    var adStateOpen = 1;
    var connection = new ActiveXObject(&quot;ADODB.CONNECTION&quot;);
    try{
        connection.Open(connectionString);
    } catch(e1){
        return null;
    }
    if (connection.State !== adStateOpen) {
        return null;
    }
    try{
        var recordset = connection.Execute(sql);
    } catch(e2){
        return null;
    }
    if (!recordset.EOF) {
        result = recordset.GetRows().toArray();
        recordset.Close();
    }
    recordset = null;
    connection.Close();
    connection = null;
    return result;
}


function writeCsvHttpHeaders(filename){
    Response.ContentType = &quot;text/csv&quot;;
    Response.Charset = &quot;utf-8&quot;;
    Response.AddHeader(&quot;Content-Disposition&quot;, 
            &quot;attachment; filename=&quot;+filename+&quot;.csv&quot;);
}

function writeXlsHttpHeaders(filename){
    Response.ContentType = &quot;application/vnd.ms-excel&quot;;
    Response.Charset = &quot;utf-8&quot;;
    Response.AddHeader(&quot;Content-Disposition&quot;, 
            &quot;attachment; filename=&quot;+filename+&quot;.xls&quot;);
}

function getXlsStart(){
    return &quot;&quot;
    + &quot;&lt;html&gt;\n&quot;
    + &quot;&lt;head&gt;\n&quot;
    + &quot;&lt;meta http-equiv=\&quot;Content-Type\&quot; &quot;
    + &quot;content=\&quot;text/html; charset=UTF-8\&quot;&gt;\n&quot;
    + &quot;&lt;style type=\&quot;text/css\&quot;&gt;\n&quot;
    + &quot;html, body, table {\n&quot;
    + &quot;    margin: 0;\n&quot;
    + &quot;    padding: 0;\n&quot;
    + &quot;    font-size: 11pt;\n&quot;
    + &quot;}\n&quot;
    + &quot;table, th, td { \n&quot;
    + &quot;    border: 0.1pt solid #D0D7E5;\n&quot;
    + &quot;    border-collapse: collapse;\n&quot;
    + &quot;    border-spacing: 0;\n&quot;
    + &quot;}\n&quot;
    + &quot;&lt;/style&gt;\n&quot;
    + &quot;&lt;/head&gt;\n&quot;
    + &quot;&lt;body&gt;\n&quot;
    + &quot;&lt;table&gt;\n&quot;
    + &quot;&quot;;
}

function getXlsEnd(){
    return &quot;&quot;
    + &quot;&lt;/table&gt;\n&quot;
    + &quot;&lt;/body&gt;\n&quot;
    + &quot;&lt;/html&gt;&quot;
    + &quot;&quot;;
}

function csvEscape(val){
    if (typeof val === &quot;number&quot;) {
        return val.toString(10).replace(&quot;.&quot;, &quot;,&quot;);
    } else if (typeof val === &quot;string&quot;) {
        if (val.indexOf(&quot;\&quot;&quot;) !== -1) {
            return &quot;\&quot;&quot;+val.replace(/&quot;/g, &quot;\&quot;\&quot;&quot;)+&quot;\&quot;&quot;;
        } else if (val.indexOf(&quot;;&quot;) !== -1) {
            return &quot;\&quot;&quot;+val+&quot;\&quot;&quot;;
        } else {
            return val;
        }
    } else if (val === null) {
        return &quot;#NULL#&quot;;
    } else if (val === undefined) {
        return &quot;#UNDEFINED#&quot;;
    } else {
        return &quot;#ERROR#&quot;;
    }
}

function writeCsv(filename, data, columnCount){
    writeCsvHttpHeaders(filename);
    // utf-8 BOM (very important for special characters)
    Response.Write(&quot;\uFEFF&quot;);
    for (var i=0, il=data.length; i&lt;il; i+=columnCount) {
        for (var j=0; j&lt;columnCount; j++) {
            Response.Write(csvEscape(data[i+j]));
            if (j !== columnCount-1) {
                Response.Write(&quot;;&quot;);
            }
        }
        Response.Write(&quot;\n&quot;);
        // prevent Response Buffering Limit Exceeded
        if (i % 1000 === 0) {
            Response.Flush();
        }
    }
}

function xlsEscape(val){
    if (typeof val === &quot;number&quot;) {
        return val.toString(10).replace(&quot;.&quot;, &quot;,&quot;);
    } else if (typeof val === &quot;string&quot;) {
        return Server.HTMLEncode(val);
    } else if (val === null)  {
        return &quot;#NULL#&quot;;
    } else if (val === undefined)  {
        return &quot;#UNDEFINED#&quot;;
    } else {
        return &quot;#ERROR#&quot;;
    }
}

function writeXls(filename, data, columnCount){
    writeXlsHttpHeaders(filename);
    Response.Write(getXlsStart());
    for (var i=0, il=data.length; i&lt;il; i+=columnCount) {
        Response.Write(&quot;&lt;tr&gt;&quot;);
        for (var j=0; j&lt;columnCount; j++) {
            Response.Write(&quot;&lt;td&gt;&quot;);
            Response.Write(xlsEscape(data[i+j]));
            Response.Write(&quot;&lt;/td&gt;&quot;);
        }
        Response.Write(&quot;&lt;/tr&gt;\n&quot;);
        // prevent Response Buffering Limit Exceeded
        if (i % 1000 === 0) {
            Response.Flush();
        }
    }
    Response.Write(getXlsEnd());
}

function main(){
    var filetype = Request.QueryString(&quot;filetype&quot;)();
    var connectionString = &quot;Provider=SQLOLEDB.1;&quot;
    + &quot;Data Source=LAPTOP\\SQLEXPRESS;&quot;
    + &quot;User ID=internal;&quot;
    + &quot;Password=internal;&quot;
    + &quot;Initial Catalog=trees_in_sql&quot;;
    var sql = &quot;&quot;
    + &quot;SELECT id \n&quot;
    + &quot;, name \n&quot;
    + &quot;FROM People \n&quot;
    + &quot;;&quot;;
    var filename = &quot;filename&quot;;
    var columnCount = 2;
    
    var data = getData(connectionString, sql);
    if (data !== null) {
        Response.Clear();
        if (filetype === &quot;csv&quot;) {
            writeCsv(filename, data, columnCount);
        } else {
            writeXls(filename, data, columnCount);
        }
    } else {
        Response.Write(&quot;Error, no data found&quot;);
    }
    Response.End();
}

main();

%&gt;
</pre>

<p>Resources:</p>
<ul>
<!--
dead link
<li><a href="http://www.netdominus.co.uk/knowledgebase/mod/resource/view.php?id=182">Styling Excel cells with mso-number-format</a></li>
&#8211;>
<li><a href="http://agoric.com/sources/software/htmltoExcel">From HTML to Excel</a></li>
<li><a href="http://stackoverflow.com/questions/440892/how-to-output-an-excel-xls-file-from-classic-asp/594928#594928">How to output an Excel *.xls file from classic ASP</a></li>
<li><a href="http://www.w3schools.com/media/media_mimeref.asp">Multimedia MIME Reference</a></li>
<li><a href="http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html">How do I prompt a &quot;Save As&quot; dialog for an accepted mime type?</a></li>
<li><a href="http://www.c-sharpcorner.com/UploadFile/kaushikborah28/79Nick08302007171404PM/79Nick.aspx">Creating a dynamic Excel using HTML</a></li>
<li><a href="http://www.phpsolvent.com/wordpress/?p=265">MS Excel is making me look bad</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.crydust.be/blog/2009/03/02/generate-excel-files-in-asp-classic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XSLT transform in asp with Microsoft.XMLDOM</title>
		<link>http://www.crydust.be/blog/2007/10/31/xslt-transform-in-asp-with-microsoftxmldom/</link>
		<comments>http://www.crydust.be/blog/2007/10/31/xslt-transform-in-asp-with-microsoftxmldom/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 14:24:56 +0000</pubDate>
		<dc:creator>Kristof Neirynck</dc:creator>
				<category><![CDATA[asp]]></category>

		<guid isPermaLink="false">http://www.crydust.be/blog/2007/10/31/xslt-transform-in-asp-with-microsoftxmldom/</guid>
		<description><![CDATA[<p>I recently had to transform an xml file into a scorm manifest file. I wanted it to be in UTF-8, but <em>Microsoft.XMLDOM</em>'s transform method disregards the <em>encoding</em> setting in <em>xsl:output</em>. The <em>transformNodeToObject</em> method doesn't. I also found out I had to use the <em>save</em> method on the output object instead of writing a file based on the <em>xml</em> property. You'll find the function I ended up writing to assist me below:</p>]]></description>
			<content:encoded><![CDATA[<p>I recently had to transform an xml file into a scorm manifest file. I wanted it to be in UTF-8, but <em>Microsoft.XMLDOM</em>&#8216;s transform method disregards the <em>encoding</em> setting in <em>xsl:output</em>. The <em>transformNodeToObject</em> method doesn&#8217;t. I also found out I had to use the <em>save</em> method on the output object instead of writing a file based on the <em>xml</em> property. You&#8217;ll find the function I ended up writing to assist me below:</p>
<span id="more-41"></span>
<pre class="prettyprint">&lt;script language=&quot;javascript&quot; runat=&quot;server&quot;&gt;
function transformXmlFile(xmlfile, xslfile, outputfile){
    var xml = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
    var xsl = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
    var out = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
    xml.async = false;
    xsl.async = false;
    out.async = false;
    xml.load(xmlfile);
    xsl.load(xslfile);
    xml.transformNodeToObject(xsl, out);
    out.save(outputfile);
    xml = null;
    xsl = null;
    out = null;
}
&lt;/script&gt;</pre>]]></content:encoded>
			<wfw:commentRss>http://www.crydust.be/blog/2007/10/31/xslt-transform-in-asp-with-microsoftxmldom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

