<?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"
	>

<channel>
	<title>Fransiscus Setiawan .NET Blog &#187; VB.NET</title>
	<atom:link href="http://fransiscuss.com/category/aspnet/vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://fransiscuss.com</link>
	<description>My notepad to share knowledge with others</description>
	<pubDate>Wed, 06 Jan 2010 05:44:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Compression in Silverlight Isolated Storage</title>
		<link>http://fransiscuss.com/compression-in-silverlight-isolated-storage/</link>
		<comments>http://fransiscuss.com/compression-in-silverlight-isolated-storage/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 04:34:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Isolated Storage]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=240</guid>
		<description><![CDATA[Isolated storage in silverlight is used to store information or object therefore we don&#8217;t need to go to database to get all the information over and over again but again to use isolated storage or not should be based on case by case. Based on the implementation of the code below, I&#8217;ve found that it [...]]]></description>
			<content:encoded><![CDATA[<p>Isolated storage in silverlight is used to store information or object therefore we don&#8217;t need to go to database to get all the information over and over again but again to use isolated storage or not should be based on case by case. Based on the implementation of the code below, I&#8217;ve found that it can compress the isolated storage file from <strong><span style="color:red">0.8Mb becoming 0.1 MB</span></strong> which is great enough for me since the quota limit is 1 mb and we try not to exceed that limit.</p>
<p>I&#8217;ve got this compression method from <a href="http://www.eggheadcafe.com/tutorials/aspnet/d566463d-83bd-486a-8633-53aa54f405bf/silverlight-2-beta-2-doi.aspx" target="_blank">Peter Bromberg blog</a>. </p>
<p>This compression method is a wrapper to SharpZip Library for Silverlight, you can download it from <a href="" target="_blank">here</a>, you need this library before using the code below. You can download the code below from <a href="" target="_blank">here</a>. </p>
<p>I&#8217;ve also created a Isolated Storage File with the assembly version as the file name to make sure that we have clean isolated storage file assuming the uncompressed version of isolated storage is already in production and we need to clean it up.  <strong>&#8220;AssemblyVersion&#8221;</strong> properties will return the property of the current version no of the running assembly. <strong>CheckIsolatedStorageFileVersion</strong> will make sure that we always have the clean isolated storage for the new assembly.</p>
<p><strong>Sample of usage</strong><br />
<strong>1. How to read/deserialize object from isolated storage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> <span style="color: #b1b100;">Dim</span> objMessageCodes <span style="color: #b1b100;">As</span> MessageCodes = GetIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of MessageCodes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;MyFile.txt&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>2. How to write/serialize object to isolated storage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">      <span style="color: #b1b100;">Dim</span> _messageCodes <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MessageCodes<span style="color: #66cc66;">&#40;</span>mListMessage<span style="color: #66cc66;">&#41;</span>
      WriteIsolatedStorage<span style="color: #66cc66;">&#40;</span>_messageCodes, <span style="color: #ff0000;">&quot;myfile.txt&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>These are the definition of the above function to serialize/deserialize object from your silverlight, this function is created based on Generic so it&#8217;s flexible enough to accept anything</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Collections</span>.<span style="color: #66cc66;">Generic</span>
Imports System.<span style="color: #66cc66;">ServiceModel</span>
Imports System.<span style="color: #66cc66;">Threading</span>
Imports System.<span style="color: #66cc66;">IO</span>
Imports System.<span style="color: #66cc66;">IO</span>.<span style="color: #66cc66;">IsolatedStorage</span>
Imports System.<span style="color: #66cc66;">Xml</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Runtime</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Reflection</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class MySL
 <span style="color: #b1b100;">Private</span> mAppStorage <span style="color: #b1b100;">As</span> IsolatedStorageFile
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' This is used to write the compressed object to Isolated Storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;param name=&quot;filename&quot;&gt;&lt;/param&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> WriteIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal obj <span style="color: #b1b100;">As</span> T, ByVal filename <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> xmlByte <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Compression.<span style="color: #66cc66;">SerializeAndCompress</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">CreateFile</span><span style="color: #66cc66;">&#40;</span>filename<span style="color: #66cc66;">&#41;</span>
                _stream.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>xmlByte, 0, xmlByte.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' this is used get the compressed object from Isolated storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;typeparam name=&quot;T&quot;&gt;&lt;/typeparam&gt;</span>
    <span style="color: #808080;">''' &lt;param name=&quot;fileName&quot;&gt;&lt;/param&gt;</span>
    <span style="color: #808080;">''' &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Function</span> GetIsolatedStorage<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal fileName <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        Try
            Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">OpenFile</span><span style="color: #66cc66;">&#40;</span>fileName, FileMode.<span style="color: #b1b100;">Open</span><span style="color: #66cc66;">&#41;</span>
                Using _reader <span style="color: #b1b100;">As</span> BinaryReader = <span style="color: #b1b100;">New</span> BinaryReader<span style="color: #66cc66;">&#40;</span>_stream<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">Dim</span> tmpBytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">ReDim</span> tmpBytes<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">Dim</span> fullBytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">Nothing</span>
                    <span style="color: #b1b100;">Dim</span> xmlStream <span style="color: #b1b100;">As</span> MemoryStream = <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                    <span style="color: #b1b100;">While</span> <span style="color: #b1b100;">True</span>
                        <span style="color: #b1b100;">Dim</span> read <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = _reader.<span style="color: #66cc66;">Read</span><span style="color: #66cc66;">&#40;</span>tmpBytes, 0, tmpBytes.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>read &lt;= 0<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                            fullBytes = xmlStream.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                            <span style="color: #b1b100;">Exit</span> <span style="color: #b1b100;">While</span>
                        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
                        xmlStream.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>tmpBytes, 0, read<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">While</span>
&nbsp;
                    <span style="color: #b1b100;">Dim</span> xmlTempbyte <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = xmlStream.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                     <span style="color: #b1b100;">Return</span> Compression.<span style="color: #66cc66;">DecompressAndDeserialize</span><span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>xmlTempbyte<span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> <span style="color: #b1b100;">Nothing</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
<span style="color: #b1b100;">Private</span> _compression <span style="color: #b1b100;">As</span> Compression = <span style="color: #b1b100;">Nothing</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> ReadOnly <span style="color: #b1b100;">Property</span> Compression<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Compression
        <span style="color: #b1b100;">Get</span>
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>_compression Is <span style="color: #b1b100;">Nothing</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                _compression = <span style="color: #b1b100;">New</span> Compression<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
            <span style="color: #b1b100;">Return</span> _compression
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Get</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Property</span>
&nbsp;
    <span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' get the assembly version</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;value&gt;&lt;/value&gt;</span>
    <span style="color: #808080;">''' &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> ReadOnly <span style="color: #b1b100;">Property</span> AssemblyVersion<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span>
        <span style="color: #b1b100;">Get</span>
            <span style="color: #b1b100;">Dim</span> <span style="color: #b1b100;">name</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = Assembly.<span style="color: #66cc66;">GetExecutingAssembly</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">FullName</span>
            <span style="color: #b1b100;">Dim</span> asmName <span style="color: #b1b100;">As</span> AssemblyName = <span style="color: #b1b100;">New</span> AssemblyName<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> asmName.<span style="color: #66cc66;">Version</span>.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">Replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Get</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Property</span>
&nbsp;
<span style="color: #808080;">''' &lt;summary&gt;</span>
    <span style="color: #808080;">''' try to clear isolated storage</span>
    <span style="color: #808080;">''' &lt;/summary&gt;</span>
    <span style="color: #808080;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> CheckIsolatedStorageFileVersion<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> isoStorage <span style="color: #b1b100;">As</span> IsolatedStorageFile = IsolatedStorageFile.<span style="color: #66cc66;">GetUserStoreForSite</span>
&nbsp;
            <span style="color: #b1b100;">If</span> <span style="color: #b1b100;">Not</span> mAppStorage.<span style="color: #66cc66;">FileExists</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion + <span style="color: #ff0000;">&quot;.txt&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                <span style="color: #808080;">'clear all the isolated storage</span>
                isoStorage.<span style="color: #66cc66;">Remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                mAppStorage.<span style="color: #66cc66;">Remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                mAppStorage = IsolatedStorageFile.<span style="color: #66cc66;">GetUserStoreForApplication</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                Using _stream <span style="color: #b1b100;">As</span> IsolatedStorageFileStream = mAppStorage.<span style="color: #66cc66;">CreateFile</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion + <span style="color: #ff0000;">&quot;.txt&quot;</span><span style="color: #66cc66;">&#41;</span>
                    Using sw <span style="color: #b1b100;">As</span> StreamWriter = <span style="color: #b1b100;">New</span> StreamWriter<span style="color: #66cc66;">&#40;</span>_stream<span style="color: #66cc66;">&#41;</span>
                        sw.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>AssemblyVersion<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #b1b100;">End</span> Using
                <span style="color: #b1b100;">End</span> Using
                <span style="color: #808080;">'Throw New Exception(&quot;Clearing!!!&quot;)</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
            Throw ex
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p><strong>Wrapper Class to SL SharpZipLib</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System
Imports System.<span style="color: #66cc66;">Text</span>
Imports System.<span style="color: #66cc66;">IO</span>
Imports System.<span style="color: #66cc66;">Collections</span>
Imports System.<span style="color: #66cc66;">Diagnostics</span>
Imports System.<span style="color: #66cc66;">Collections</span>.<span style="color: #66cc66;">Generic</span>
Imports System.<span style="color: #66cc66;">Runtime</span>.<span style="color: #66cc66;">Serialization</span>
Imports ICSharpCode.<span style="color: #66cc66;">SharpZipLib</span>.<span style="color: #66cc66;">Zip</span>.<span style="color: #66cc66;">Compression</span>
Imports System.<span style="color: #66cc66;">Xml</span>.<span style="color: #66cc66;">Serialization</span>
Imports System.<span style="color: #66cc66;">Text</span>.<span style="color: #66cc66;">RegularExpressions</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class Compression
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Sub</span> <span style="color: #b1b100;">New</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Serialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal inst <span style="color: #b1b100;">As</span> T<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> dcs <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> DataContractSerializer<span style="color: #66cc66;">&#40;</span>GetType<span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream
            dcs.<span style="color: #66cc66;">WriteObject</span><span style="color: #66cc66;">&#40;</span>ms, inst<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Deserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal objectData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        <span style="color: #b1b100;">Dim</span> dcs <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> DataContractSerializer<span style="color: #66cc66;">&#40;</span>GetType<span style="color: #66cc66;">&#40;</span>T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span>objectData<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Return</span> CType<span style="color: #66cc66;">&#40;</span>dcs.<span style="color: #66cc66;">ReadObject</span><span style="color: #66cc66;">&#40;</span>ms<span style="color: #66cc66;">&#41;</span>, T<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> SerializeAndCompress<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal inst <span style="color: #b1b100;">As</span> T<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> b <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Serialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>inst<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Return</span> Compress<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> DecompressAndDeserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> T
        <span style="color: #b1b100;">Dim</span> bytes <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = Decompress<span style="color: #66cc66;">&#40;</span>bytData<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Return</span> Deserialize<span style="color: #66cc66;">&#40;</span>Of T<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal strInput <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
            <span style="color: #b1b100;">Dim</span> bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = System.<span style="color: #66cc66;">Text</span>.<span style="color: #66cc66;">Encoding</span>.<span style="color: #66cc66;">UTF8</span>.<span style="color: #66cc66;">GetBytes</span><span style="color: #66cc66;">&#40;</span>strInput<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span>, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
&nbsp;
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span>, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
&nbsp;
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Compress<span style="color: #66cc66;">&#40;</span>ByVal bytData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, ByVal ParamArray ratio <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        <span style="color: #b1b100;">Dim</span> compRatio <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = <span style="color: #cc66cc;">9</span>
        Try
            <span style="color: #b1b100;">If</span> ratio<span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span> &gt; 0 <span style="color: #b1b100;">Then</span>
                compRatio = ratio<span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
        Catch
&nbsp;
        <span style="color: #b1b100;">End</span> Try
&nbsp;
        Try
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> defl <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Deflater<span style="color: #66cc66;">&#40;</span>compRatio, <span style="color: #b1b100;">False</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            Using s <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">DeflaterOutputStream</span><span style="color: #66cc66;">&#40;</span>ms, defl<span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>bytData, 0, bytData.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                s.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> DirectCast<span style="color: #66cc66;">&#40;</span>ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        Catch
            Throw
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Decompress<span style="color: #66cc66;">&#40;</span>ByVal bytInput <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span>bytInput, 0, bytInput.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> bytResult <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">Nothing</span>
            <span style="color: #b1b100;">Dim</span> strResult <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #66cc66;">Empty</span>
            <span style="color: #b1b100;">Dim</span> writeData <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">New</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4095</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
            Using s2 <span style="color: #b1b100;">As</span> Stream = <span style="color: #b1b100;">New</span> Streams.<span style="color: #66cc66;">InflaterInputStream</span><span style="color: #66cc66;">&#40;</span>ms<span style="color: #66cc66;">&#41;</span>
                bytResult = ReadFullStream<span style="color: #66cc66;">&#40;</span>s2<span style="color: #66cc66;">&#41;</span>
                s2.<span style="color: #b1b100;">Close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> Using
&nbsp;
            <span style="color: #b1b100;">Return</span> bytResult
        Catch
            Throw
        <span style="color: #b1b100;">End</span> Try
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> ReadFullStream<span style="color: #66cc66;">&#40;</span>ByVal stream <span style="color: #b1b100;">As</span> Stream<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> buffer <span style="color: #b1b100;">As</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #b1b100;">New</span> Byte<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32767</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
        Using ms <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> MemoryStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">While</span> <span style="color: #b1b100;">True</span>
                <span style="color: #b1b100;">Dim</span> read <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = stream.<span style="color: #66cc66;">Read</span><span style="color: #66cc66;">&#40;</span>buffer, 0, buffer.<span style="color: #66cc66;">Length</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">If</span> read &lt;= 0 <span style="color: #b1b100;">Then</span>
                    <span style="color: #b1b100;">Return</span> ms.<span style="color: #66cc66;">ToArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
                ms.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>buffer, 0, read<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">While</span>
        <span style="color: #b1b100;">End</span> Using
&nbsp;
        <span style="color: #b1b100;">Return</span> buffer
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
<span style="color: #b1b100;">End</span> Class</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/compression-in-silverlight-isolated-storage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>FormsAuthentication.GetRedirectUrl only get the first parameter of querystring</title>
		<link>http://fransiscuss.com/formsauthenticationgetredirecturl-only-get-the-first-parameter-of-querystring/</link>
		<comments>http://fransiscuss.com/formsauthenticationgetredirecturl-only-get-the-first-parameter-of-querystring/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 05:53:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Forms Authentication]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=236</guid>
		<description><![CDATA[I found the issue with FormsAuthentication.GetRedirectUrl when it redirects then it redirects with the first querystring that you have while in fact you might have more than one querystring
e.g http://localhost/myweb/login.aspx?returnurl=myview.aspx?viewID=123&#38;viewname=abc&#38;viewall=false then the standard FormsAuthentication will redirect to http://localhost/myweb/myview.aspx?viewID=123
but where&#8217;s the remaining viewname querystring and viewall querystring??to fix this, just use the code below to pick [...]]]></description>
			<content:encoded><![CDATA[<p>I found the issue with FormsAuthentication.GetRedirectUrl when it redirects then it redirects with the first querystring that you have while in fact you might have more than one querystring</p>
<p>e.g <a href="http://localhost/myweb/login.aspx?returnurl=myview.aspx?viewID=123&amp;viewname=abc&amp;viewall=false">http://localhost/myweb/login.aspx?returnurl=myview.aspx?viewID=123&amp;viewname=abc&amp;viewall=false</a> then the standard FormsAuthentication will redirect to <a href="http://localhost/myweb/myview.aspx?viewID=123">http://localhost/myweb/myview.aspx?viewID=123</a></p>
<p>but where&#8217;s the remaining viewname querystring and viewall querystring??to fix this, just use the code below to pick the remaining querystring</p>
<p><strong>Methods:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">  <span style="color: #808080;">'this is used to fix the issue with FormsAuthentication.GetRedirectUrl only pick the first query string</span>
            <span style="color: #808080;">'get the original Redirect URL</span>
            <span style="color: #b1b100;">Dim</span> redirectUrl <span style="color: #b1b100;">As</span> StringBuilder = <span style="color: #b1b100;">New</span> StringBuilder<span style="color: #66cc66;">&#40;</span>FormsAuthentication.<span style="color: #66cc66;">GetRedirectUrl</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span>, <span style="color: #b1b100;">True</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> coll <span style="color: #b1b100;">As</span> NameValueCollection = objRequest.<span style="color: #66cc66;">QueryString</span>
&nbsp;
            <span style="color: #808080;">'iterate through every key in query string</span>
            <span style="color: #808080;">'add the missing query string</span>
            <span style="color: #b1b100;">For</span> Each key <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> In coll.<span style="color: #66cc66;">AllKeys</span>
                <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">Compare</span><span style="color: #66cc66;">&#40;</span>key, <span style="color: #ff0000;">&quot;returnurl&quot;</span>, <span style="color: #b1b100;">True</span><span style="color: #66cc66;">&#41;</span> &lt;&gt; 0<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                    <span style="color: #b1b100;">Dim</span> values <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = coll.<span style="color: #66cc66;">GetValues</span><span style="color: #66cc66;">&#40;</span>key<span style="color: #66cc66;">&#41;</span>
&nbsp;
                    <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>values.<span style="color: #66cc66;">Length</span> &gt; 0<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                        <span style="color: #b1b100;">Dim</span> pair <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = <span style="color: #b1b100;">String</span>.<span style="color: #b1b100;">Format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;{0}={1}&quot;</span>, key, values<span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>redirectUrl.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">IndexOf</span><span style="color: #66cc66;">&#40;</span>pair<span style="color: #66cc66;">&#41;</span> &lt; 0<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                            redirectUrl.<span style="color: #66cc66;">Append</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&amp;&quot;</span> + pair<span style="color: #66cc66;">&#41;</span>
                        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
                    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
                <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
            <span style="color: #b1b100;">Next</span>
&nbsp;
            <span style="color: #808080;">'this is to retain the original URL as in the query string</span>
            objResponse.<span style="color: #66cc66;">Redirect</span><span style="color: #66cc66;">&#40;</span>redirectUrl.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/formsauthenticationgetredirecturl-only-get-the-first-parameter-of-querystring/feed/</wfw:commentRss>
		</item>
		<item>
		<title>an activex control on this page might be unsafe to interact with other parts of the page. do you want to allow this interaction?</title>
		<link>http://fransiscuss.com/an-activex-control-on-this-page-might-be-unsafe-to-interact-with-other-parts-of-the-page-do-you-want-to-allow-this-interaction/</link>
		<comments>http://fransiscuss.com/an-activex-control-on-this-page-might-be-unsafe-to-interact-with-other-parts-of-the-page-do-you-want-to-allow-this-interaction/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 06:18:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=233</guid>
		<description><![CDATA[I keep getting this message &#8220;an activex control on this page might be unsafe to interact with other parts of the page. do you want to allow this interaction&#8221; when I try to access a page that use Javascript to access ActiveX Code. I&#8217;ve spent quite sometime to get rid of this error message and [...]]]></description>
			<content:encoded><![CDATA[<p>I keep getting this message &#8220;an activex control on this page might be unsafe to interact with other parts of the page. do you want to allow this interaction&#8221; when I try to access a page that use Javascript to access ActiveX Code. I&#8217;ve spent quite sometime to get rid of this error message and I found out that</p>
<ol>
<li>The code need implement IObjectSafety Interface</li>
<li>You need to digitally sign the code with valid certificate</li>
</ol>
<p><strong>Step 1 :</strong> Detail on how to implement IObjectSafety<br />
-Create an interface file called as IObjectSafety.vb/IObjectSafety.cs</p>
<p>CSharp (IObjectSafety.cs) :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>ComImport<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span>Guid<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CB5BDC81-93C1-11CF-8F20-00805F2CD064&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span>InterfaceType<span style="color: #000000;">&#40;</span>ComInterfaceType.<span style="color: #0000FF;">InterfaceIsIUnknown</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #FF0000;">interface</span> IObjectSafety <span style="color: #000000;">&#123;</span>
   <span style="color: #000000;">&#91;</span>PreserveSig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
   <span style="color: #FF0000;">int</span> GetInterfaceSafetyOptions<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> Guid riid, <span style="color: #0600FF;">out</span> <span style="color: #FF0000;">int</span> pdwSupportedOptions, <span style="color: #0600FF;">out</span> <span style="color: #FF0000;">int</span> pdwEnabledOptions<span style="color: #000000;">&#41;</span>;
&nbsp;
   <span style="color: #000000;">&#91;</span>PreserveSig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
   <span style="color: #FF0000;">int</span> SetInterfaceSafetyOptions<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> Guid riid, <span style="color: #FF0000;">int</span> dwOptionSetMask, <span style="color: #FF0000;">int</span> dwEnabledOptions<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Runtime</span>.<span style="color: #66cc66;">InteropServices</span>
&nbsp;
&lt;ComImport<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&gt; _
&lt;Guid<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;CB5BDC81-93C1-11CF-8F20-00805F2CD064&quot;</span><span style="color: #66cc66;">&#41;</span>&gt; _
&lt;InterfaceType<span style="color: #66cc66;">&#40;</span>ComInterfaceType.<span style="color: #66cc66;">InterfaceIsIUnknown</span><span style="color: #66cc66;">&#41;</span>&gt; _
Interface IObjectSafety
    &lt;PreserveSig<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&gt; _
    <span style="color: #b1b100;">Function</span> GetInterfaceSafetyOptions<span style="color: #66cc66;">&#40;</span>ByRef riid <span style="color: #b1b100;">As</span> Guid, ByRef pdwSupportedOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>, ByRef pdwEnabledOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>
&nbsp;
    &lt;PreserveSig<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&gt; _
    <span style="color: #b1b100;">Function</span> SetInterfaceSafetyOptions<span style="color: #66cc66;">&#40;</span>ByRef riid <span style="color: #b1b100;">As</span> Guid, ByVal dwOptionSetMask <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>, ByVal dwEnabledOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>
<span style="color: #b1b100;">End</span> Interface</pre></div></div>

<p>in your ActiveX code you need to implement IObjectSafety</p>
<p>CSharp:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">&nbsp;</pre></div></div>

<p>VB.NET:</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">&lt;ProgId<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Fransiscus.Authentication.ClientUtility&quot;</span><span style="color: #66cc66;">&#41;</span>&gt; _
&lt;ClassInterface<span style="color: #66cc66;">&#40;</span>ClassInterfaceType.<span style="color: #66cc66;">AutoDual</span><span style="color: #66cc66;">&#41;</span>, ComSourceInterfaces<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ControlEvents&quot;</span><span style="color: #66cc66;">&#41;</span>&gt; _
&lt;Guid<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;0577147B-6941-4f15-9EFB-2551FEB3D6CC&quot;</span><span style="color: #66cc66;">&#41;</span>&gt; _
&lt;ComVisible<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">True</span><span style="color: #66cc66;">&#41;</span>&gt; _
<span style="color: #b1b100;">Public</span> NotInheritable Class ClientUtility
    <span style="color: #b1b100;">Implements</span> IObjectSafety
&nbsp;
&nbsp;
#Region <span style="color: #ff0000;">&quot;IObjectSafety Constants&quot;</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Const</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = &amp;H1
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Const</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = &amp;H2
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Const</span> S_OK <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> = 0
&nbsp;
#End Region
&nbsp;
#Region <span style="color: #ff0000;">&quot;IObjectSafety Methods&quot;</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> GetInterfaceSafetyOptions<span style="color: #66cc66;">&#40;</span>ByRef riid <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Guid</span>, ByRef pdwSupportedOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>, ByRef pdwEnabledOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> <span style="color: #b1b100;">Implements</span> IObjectSafety.<span style="color: #66cc66;">GetInterfaceSafetyOptions</span>
        pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER <span style="color: #b1b100;">Or</span> INTERFACESAFE_FOR_UNTRUSTED_DATA
        pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER <span style="color: #b1b100;">Or</span> INTERFACESAFE_FOR_UNTRUSTED_DATA
        <span style="color: #b1b100;">Return</span> S_OK
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> SetInterfaceSafetyOptions<span style="color: #66cc66;">&#40;</span>ByRef riid <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Guid</span>, ByVal dwOptionSetMask <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span>, ByVal dwEnabledOptions <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span> <span style="color: #b1b100;">Implements</span> IObjectSafety.<span style="color: #66cc66;">SetInterfaceSafetyOptions</span>
        <span style="color: #b1b100;">Return</span> S_OK
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
&nbsp;
#End Region</pre></div></div>

<p>CSharp:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>ProgId<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Fransiscus.Authentication.ClientUtility&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> 
<span style="color: #000000;">&#91;</span>ClassInterface<span style="color: #000000;">&#40;</span>ClassInterfaceType.<span style="color: #0000FF;">AutoDual</span><span style="color: #000000;">&#41;</span>, ComSourceInterfaces<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ControlEvents&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> 
<span style="color: #000000;">&#91;</span>Guid<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0577147B-6941-4f15-9EFB-2551FEB3D6CC&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> 
<span style="color: #000000;">&#91;</span>ComVisible<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> 
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">sealed</span> <span style="color: #FF0000;">class</span> ClientUtility <span style="color: #008000;">:</span> IObjectSafety 
<span style="color: #000000;">&#123;</span> 
&nbsp;
&nbsp;
    <span style="color: #008080;">#region &quot;IObjectSafety Constants&quot; </span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER <span style="color: #008000;">=</span> 0x1; 
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span style="color: #008000;">=</span> 0x2; 
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> S_OK <span style="color: #008000;">=</span> 0; 
&nbsp;
    <span style="color: #008080;">#endregion </span>
&nbsp;
    <span style="color: #008080;">#region &quot;IObjectSafety Methods&quot; </span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> GetInterfaceSafetyOptions<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Guid</span> riid, <span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> pdwSupportedOptions, <span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> pdwEnabledOptions<span style="color: #000000;">&#41;</span> 
    <span style="color: #000000;">&#123;</span> 
        pdwSupportedOptions <span style="color: #008000;">=</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; 
        pdwEnabledOptions <span style="color: #008000;">=</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; 
        <span style="color: #0600FF;">return</span> S_OK; 
    <span style="color: #000000;">&#125;</span> 
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> SetInterfaceSafetyOptions<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Guid</span> riid, <span style="color: #FF0000;">int</span> dwOptionSetMask, <span style="color: #FF0000;">int</span> dwEnabledOptions<span style="color: #000000;">&#41;</span> 
    <span style="color: #000000;">&#123;</span> 
        <span style="color: #0600FF;">return</span> S_OK; 
    <span style="color: #000000;">&#125;</span> 
<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><Strong>Step 2:</strong><br />
You need to obtain certificate and sign it, You also need Windows Server 2008 SDK to sign your code using SignTool.exe (type Signtool SignWizard in command prompt to follow the wizard and sign your DLL)<br />For more detail please open verisign website (http://www.verisign.com/support/code-signing-support/code-signing/identity-authentication.html) or click <a href="http://www.verisign.com/support/code-signing-support/code-signing/identity-authentication.html" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/an-activex-control-on-this-page-might-be-unsafe-to-interact-with-other-parts-of-the-page-do-you-want-to-allow-this-interaction/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Upload Multiple Files to FTP in .NET</title>
		<link>http://fransiscuss.com/upload-multiple-files-to-ftp-in-net/</link>
		<comments>http://fransiscuss.com/upload-multiple-files-to-ftp-in-net/#comments</comments>
		<pubDate>Sun, 24 May 2009 12:47:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Asynchronous Upload]]></category>

		<category><![CDATA[The remote server returned an error: (503) Bad sequence of commands]]></category>

		<category><![CDATA[Upload Files to FTP]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=227</guid>
		<description><![CDATA[I&#8217;ve played around with FTP couple of weeks back. My application is required to feed FTP folder with 1000+ files daily. I&#8217;ve been googling around and I found one of the methods is to use WebApplication so I decided to put this WebApplication method to upload while iterating every single files in the directory. After 5 files, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve played around with FTP couple of weeks back. My application is required to feed FTP folder with 1000+ files daily. I&#8217;ve been googling around and I found one of the methods is to use <strong>WebApplication</strong> so I decided to put this WebApplication method to upload while iterating every single files in the directory. After 5 files, it keeps giving me error <strong>The remote server returned an error: (503) Bad sequence of commands. </strong>Strangely the only the first 4 files always uploaded successfully, my thought was the FTP server forcely terminated the connection which is right. After googling I found that we should set <strong>KeepAlive</strong> property to false which means new connection is always created instead of maintained but unfortunately <strong>WebClient</strong> class doesn&#8217;t have KeepAlive property. Finally, I&#8217;ve come up with this code which solves my issue in uploading 1000+ files one after the other by doing Asynchronous Upload</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span>;
&nbsp;
<span style="color: #0600FF;">namespace</span> Helpers
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FtpHelpers
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FtpState
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">private</span> ManualResetEvent wait;
            <span style="color: #0600FF;">private</span> FtpWebRequest request;
            <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> fileName;
            <span style="color: #0600FF;">private</span> Exception operationException <span style="color: #008000;">=</span> null;
            <span style="color: #FF0000;">string</span> status;
&nbsp;
            <span style="color: #0600FF;">public</span> FtpState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                wait <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ManualResetEvent<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">public</span> ManualResetEvent OperationComplete
            <span style="color: #000000;">&#123;</span>
                get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> wait; <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">public</span> FtpWebRequest Request
            <span style="color: #000000;">&#123;</span>
                get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> request; <span style="color: #000000;">&#125;</span>
                set <span style="color: #000000;">&#123;</span> request <span style="color: #008000;">=</span> value; <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FileName
            <span style="color: #000000;">&#123;</span>
                get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> fileName; <span style="color: #000000;">&#125;</span>
                set <span style="color: #000000;">&#123;</span> fileName <span style="color: #008000;">=</span> value; <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">public</span> Exception OperationException
            <span style="color: #000000;">&#123;</span>
                get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> operationException; <span style="color: #000000;">&#125;</span>
                set <span style="color: #000000;">&#123;</span> operationException <span style="color: #008000;">=</span> value; <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> StatusDescription
            <span style="color: #000000;">&#123;</span>
                get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> status; <span style="color: #000000;">&#125;</span>
                set <span style="color: #000000;">&#123;</span> status <span style="color: #008000;">=</span> value; <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AsynchronousUpload<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> destinationPath, <span style="color: #FF0000;">string</span> sourcePath, <span style="color: #FF0000;">string</span> userName, <span style="color: #FF0000;">string</span> password<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Create a Uri instance with the specified URI string.</span>
            <span style="color: #008080; font-style: italic;">// If the URI is not correctly formed, the Uri constructor</span>
            <span style="color: #008080; font-style: italic;">// will throw an exception.</span>
            ManualResetEvent waitObject;
&nbsp;
            Uri target <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Uri<span style="color: #000000;">&#40;</span>destinationPath<span style="color: #000000;">&#41;</span>;
            <span style="color: #FF0000;">string</span> fileName <span style="color: #008000;">=</span> sourcePath;
            FtpState state <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FtpState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            FtpWebRequest request <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>FtpWebRequest<span style="color: #000000;">&#41;</span>WebRequest.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>target<span style="color: #000000;">&#41;</span>;
            request.<span style="color: #0000FF;">Method</span> <span style="color: #008000;">=</span> WebRequestMethods.<span style="color: #0000FF;">Ftp</span>.<span style="color: #0000FF;">UploadFile</span>;
            request.<span style="color: #0000FF;">KeepAlive</span> <span style="color: #008000;">=</span> false;
            request.<span style="color: #0000FF;">Proxy</span> <span style="color: #008000;">=</span> null;
&nbsp;
            <span style="color: #008080; font-style: italic;">// This example uses anonymous logon.</span>
            <span style="color: #008080; font-style: italic;">// The request is anonymous by default; the credential does not have to be specified. </span>
            <span style="color: #008080; font-style: italic;">// The example specifies the credential only to</span>
            <span style="color: #008080; font-style: italic;">// control how actions are logged on the server.</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>userName<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>password<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                request.<span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NetworkCredential<span style="color: #000000;">&#40;</span>userName, password<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Store the request in the object that we pass into the</span>
            <span style="color: #008080; font-style: italic;">// asynchronous operations.</span>
            state.<span style="color: #0000FF;">Request</span> <span style="color: #008000;">=</span> request;
            state.<span style="color: #0000FF;">FileName</span> <span style="color: #008000;">=</span> fileName;
&nbsp;
            <span style="color: #008080; font-style: italic;">// Get the event to wait on.</span>
            waitObject <span style="color: #008000;">=</span> state.<span style="color: #0000FF;">OperationComplete</span>;
&nbsp;
            <span style="color: #008080; font-style: italic;">// Asynchronously get the stream for the file contents.</span>
            request.<span style="color: #0000FF;">BeginGetRequestStream</span><span style="color: #000000;">&#40;</span>
                <span style="color: #008000;">new</span> AsyncCallback<span style="color: #000000;">&#40;</span>EndGetStreamCallback<span style="color: #000000;">&#41;</span>,
                state
            <span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #008080; font-style: italic;">// Block the current thread until all operations are complete.</span>
            waitObject.<span style="color: #0000FF;">WaitOne</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #008080; font-style: italic;">// The operations either completed or threw an exception.</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>state.<span style="color: #0000FF;">OperationException</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">throw</span> state.<span style="color: #0000FF;">OperationException</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> EndGetStreamCallback<span style="color: #000000;">&#40;</span>IAsyncResult ar<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            FtpState state <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>FtpState<span style="color: #000000;">&#41;</span>ar.<span style="color: #0000FF;">AsyncState</span>;
&nbsp;
            Stream requestStream <span style="color: #008000;">=</span> null;
            <span style="color: #008080; font-style: italic;">// End the asynchronous call to get the request stream.</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                requestStream <span style="color: #008000;">=</span> state.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">EndGetRequestStream</span><span style="color: #000000;">&#40;</span>ar<span style="color: #000000;">&#41;</span>;
                <span style="color: #008080; font-style: italic;">// Copy the file contents to the request stream.</span>
                <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">int</span> bufferLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">2048</span>;
                <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> buffer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span>bufferLength<span style="color: #000000;">&#93;</span>;
                <span style="color: #FF0000;">int</span> count <span style="color: #008000;">=</span> 0;
                <span style="color: #FF0000;">int</span> readBytes <span style="color: #008000;">=</span> 0;
                FileStream stream <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">OpenRead</span><span style="color: #000000;">&#40;</span>state.<span style="color: #0000FF;">FileName</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #0600FF;">do</span>
                <span style="color: #000000;">&#123;</span>
                    readBytes <span style="color: #008000;">=</span> stream.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span>buffer, 0, bufferLength<span style="color: #000000;">&#41;</span>;
                    requestStream.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>buffer, 0, readBytes<span style="color: #000000;">&#41;</span>;
                    count <span style="color: #008000;">+=</span> readBytes;
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>readBytes <span style="color: #008000;">!=</span> 0<span style="color: #000000;">&#41;</span>;
                <span style="color: #008080; font-style: italic;">// IMPORTANT: Close the request stream before sending the request.</span>
                requestStream.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #008080; font-style: italic;">// Asynchronously get the response to the upload request.</span>
                state.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">BeginGetResponse</span><span style="color: #000000;">&#40;</span>
                    <span style="color: #008000;">new</span> AsyncCallback<span style="color: #000000;">&#40;</span>EndGetResponseCallback<span style="color: #000000;">&#41;</span>,
                    state
                <span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Return exceptions to the main application thread.</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception e<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                state.<span style="color: #0000FF;">OperationException</span> <span style="color: #008000;">=</span> e;
                state.<span style="color: #0000FF;">OperationComplete</span>.<span style="color: #0000FF;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                return;
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// The EndGetResponseCallback method  </span>
        <span style="color: #008080; font-style: italic;">// completes a call to BeginGetResponse.</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> EndGetResponseCallback<span style="color: #000000;">&#40;</span>IAsyncResult ar<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            FtpState state <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>FtpState<span style="color: #000000;">&#41;</span>ar.<span style="color: #0000FF;">AsyncState</span>;
            FtpWebResponse response <span style="color: #008000;">=</span> null;
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                response <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>FtpWebResponse<span style="color: #000000;">&#41;</span>state.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">EndGetResponse</span><span style="color: #000000;">&#40;</span>ar<span style="color: #000000;">&#41;</span>;
                response.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                state.<span style="color: #0000FF;">StatusDescription</span> <span style="color: #008000;">=</span> response.<span style="color: #0000FF;">StatusDescription</span>;
                <span style="color: #008080; font-style: italic;">// Signal the main application thread that </span>
                <span style="color: #008080; font-style: italic;">// the operation is complete.</span>
                state.<span style="color: #0000FF;">OperationComplete</span>.<span style="color: #0000FF;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Return exceptions to the main application thread.</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception e<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                state.<span style="color: #0000FF;">OperationException</span> <span style="color: #008000;">=</span> e;
                state.<span style="color: #0000FF;">OperationComplete</span>.<span style="color: #0000FF;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">#Region <span style="color: #ff0000;">&quot;Properties&quot;</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> _ftpUploader <span style="color: #b1b100;">As</span> FtpHelpers = <span style="color: #b1b100;">Nothing</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> ReadOnly <span style="color: #b1b100;">Property</span> FtpUploader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> FtpHelpers
        <span style="color: #b1b100;">Get</span>
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>_ftpUploader Is <span style="color: #b1b100;">Nothing</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                _ftpUploader = <span style="color: #b1b100;">New</span> FtpHelpers<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
            <span style="color: #b1b100;">Return</span> _ftpUploader
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Get</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Property</span>
&nbsp;
#End Region
&nbsp;
<span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ProcessFilesToFTP<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        <span style="color: #808080;">' make a reference to a directory</span>
        <span style="color: #b1b100;">Dim</span> di <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> IO.<span style="color: #66cc66;">DirectoryInfo</span><span style="color: #66cc66;">&#40;</span>ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;OutputZIPDirectory&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Dim</span> jobFiles <span style="color: #b1b100;">As</span> IO.<span style="color: #66cc66;">FileInfo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = di.<span style="color: #66cc66;">GetFiles</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Console.<span style="color: #66cc66;">WriteLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">String</span>.<span style="color: #b1b100;">Format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;FTP Location: {0}&quot;</span>, ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ftplocation&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        <span style="color: #808080;">'list the names of all files in the specified directory</span>
        <span style="color: #b1b100;">For</span> Each jobFile <span style="color: #b1b100;">As</span> IO.<span style="color: #66cc66;">FileInfo</span> In jobFiles
&nbsp;
            <span style="color: #808080;">'process only zip file</span>
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>jobFile.<span style="color: #66cc66;">FullName</span>.<span style="color: #66cc66;">Contains</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;zip&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                Console.<span style="color: #66cc66;">WriteLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">String</span>.<span style="color: #b1b100;">Format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Upload file {0}&quot;</span>, jobFile.<span style="color: #b1b100;">Name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
                FtpUploader.<span style="color: #66cc66;">AsynchronousUpload</span><span style="color: #66cc66;">&#40;</span>ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ftplocation&quot;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;/&quot;</span> + jobFile.<span style="color: #b1b100;">Name</span>, jobFile.<span style="color: #66cc66;">FullName</span>, _
                                   ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ftpuser&quot;</span><span style="color: #66cc66;">&#41;</span>, _
                                   ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ftppassword&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
        <span style="color: #b1b100;">Next</span>
&nbsp;
        Console.<span style="color: #66cc66;">WriteLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">String</span>.<span style="color: #b1b100;">Format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;XML files has been uploaded to {0}&quot;</span>, ConfigurationManager.<span style="color: #66cc66;">AppSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ftplocation&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></pre></div></div>

<p>The drawback with this code is in the FTP connection where the connection always reinitialized for every single file.</p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/upload-multiple-files-to-ftp-in-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>the server committed a protocol violation section= responsestatusline</title>
		<link>http://fransiscuss.com/the-server-committed-a-protocol-violation-section-responsestatusline/</link>
		<comments>http://fransiscuss.com/the-server-committed-a-protocol-violation-section-responsestatusline/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 00:41:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=140</guid>
		<description><![CDATA[I&#8217;ve got this error and try to spend almost an hour to resolve this:
&#8220;the server committed a protocol violation section= responsestatusline&#8221;  when I tried to get the response back from the payment gateway.  It happens when you send HTTP Request one after another on the same page. The solution is to add unsafeheaderparsing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got this error and try to spend almost an hour to resolve this:</p>
<p>&#8220;the server committed a protocol violation section= responsestatusline&#8221;  when I tried to get the response back from the payment gateway.  It happens when you send HTTP Request one after another on the same page. The solution is to add unsafeheaderparsing to true  in web.config and to seet keepAlive property to false from the http request it self</p>
<p><strong>Web.Config</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span><span style="color: #000000;">system.<span style="color: #0000FF;">net</span></span><span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>defaultProxy<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>proxy usesystemdefault<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> bypassonlocal<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> proxyaddress<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://myproxy&quot;</span><span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;/</span>defaultProxy<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>settings<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>httpWebRequest useUnsafeHeaderParsing<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span><span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;/</span>settings<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>mailSettings<span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>smtp from<span style="color: #008000;">=</span><span style="color: #666666;">&quot;mail@mail.com.au&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>network host<span style="color: #008000;">=</span><span style="color: #666666;">&quot;10.2.30.51&quot;</span><span style="color: #008000;">/&gt;</span>
      <span style="color: #008000;">&lt;/</span>smtp<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>mailSettings <span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span><span style="color: #000000;">system.<span style="color: #0000FF;">net</span></span><span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p><strong>Calling Code:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">   <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> SendXML<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strSend <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span>
        <span style="color: #0600FF;">Dim</span> blnSuccess <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
        <span style="color: #0600FF;">Dim</span> objSendXML <span style="color: #FF8000;">As</span> XmlDocument
        <span style="color: #0600FF;">Dim</span> objRequest <span style="color: #FF8000;">As</span> HttpWebRequest
        <span style="color: #0600FF;">Dim</span> mywriter <span style="color: #FF8000;">As</span> StreamWriter
        <span style="color: #0600FF;">Dim</span> objResponse <span style="color: #FF8000;">As</span> HttpWebResponse
        <span style="color: #0600FF;">Dim</span> objReturnedXML <span style="color: #FF8000;">As</span> XmlDataDocument
        <span style="color: #0600FF;">Dim</span> objElementRoot <span style="color: #FF8000;">As</span> XmlElement
        <span style="color: #0600FF;">Dim</span> objElementTransaction <span style="color: #FF8000;">As</span> XmlNode
        <span style="color: #0600FF;">Dim</span> objElementCreditCardInfo <span style="color: #FF8000;">As</span> XmlNode
        <span style="color: #0600FF;">Dim</span> x <span style="color: #FF8000;">As</span> XmlNode
&nbsp;
        <span style="color: #0600FF;">Dim</span> strApproved <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">String</span>.<span style="color: #FF8000;">Empty</span>
        <span style="color: #0600FF;">Dim</span> blnCreditCardInfo <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">' Must reset the variable incase of error</span>
        <span style="color: #FF8000;">Me</span>._Paid <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
&nbsp;
        objSendXML <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> XmlDocument
        objRequest <span style="color: #008000;">=</span> WebRequest.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>strPaymentURL<span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">'if it is using proxy/behind proxy</span>
        <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>UseProxy <span style="color: #804040;">And</span> <span style="color: #804040;">Not</span> <span style="color: #000000;">&#40;</span><span style="color: #FF8000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>ProxyServer<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            objRequest.<span style="color: #0000FF;">Proxy</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> System.<span style="color: #0000FF;">Net</span>.<span style="color: #0000FF;">WebProxy</span><span style="color: #000000;">&#40;</span>ProxyServer, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'if there is credential</span>
            <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>UseDefaultCredential<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
                objRequest.<span style="color: #0000FF;">Proxy</span>.<span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> CredentialCache.<span style="color: #0000FF;">DefaultCredentials</span>
            <span style="color: #FF8000;">Else</span>
                objRequest.<span style="color: #0000FF;">Proxy</span>.<span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> NetworkCredential<span style="color: #000000;">&#40;</span>UserName, Password<span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        objRequest.<span style="color: #0600FF;">Method</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;POST&quot;</span>
        objRequest.<span style="color: #0000FF;">ContentLength</span> <span style="color: #008000;">=</span> strSend.<span style="color: #0000FF;">Length</span>
        objRequest.<span style="color: #0000FF;">ContentType</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;text/xml&quot;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'to solve protocol violation problem</span>
        objRequest.<span style="color: #0000FF;">KeepAlive</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/the-server-committed-a-protocol-violation-section-responsestatusline/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Invalid postback or call argument</title>
		<link>http://fransiscuss.com/invalid-postback-or-call-argument/</link>
		<comments>http://fransiscuss.com/invalid-postback-or-call-argument/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 22:52:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=133</guid>
		<description><![CDATA[It&#8217;s quite often I have this error because of the content has been changed during postback or because of the control id. I&#8217;ve read most of the article suggested to disable the event validation by putting this on the page  which is loosen up the security of that particular page. I found the other [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite often I have this error because of the content has been changed during postback or because of the control id. I&#8217;ve read most of the article suggested to disable the event validation by putting this on the page <%@Page EnableEventValidation="true" %> which is loosen up the security of that particular page. I found the other method without need to change the EnableEventValidation to false. What i found is that you can reregister your control on the render method<br />
<strong>VB.NET</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">Protected Overrides <span style="color: #0600FF;">Sub</span> Render<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> writer <span style="color: #FF8000;">As</span> HtmlTextWriter<span style="color: #000000;">&#41;</span>
&nbsp;
Register<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">MyBase</span>.<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span>writer<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Register<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> ctrl <span style="color: #FF8000;">As</span> Control<span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> c <span style="color: #FF8000;">As</span> Control In ctrl.<span style="color: #0000FF;">Controls</span>
&nbsp;
Register<span style="color: #000000;">&#40;</span>c<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #FF8000;">Next</span>
&nbsp;
Page.<span style="color: #0000FF;">ClientScript</span>.<span style="color: #0000FF;">RegisterForEventValidation</span><span style="color: #000000;">&#40;</span>ctrl.<span style="color: #0000FF;">UniqueID</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><strong>C#</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>HtmlTextWriter writer<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000000;">&#123;</span>
Register<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span>;base.<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span>writer<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Register<span style="color: #000000;">&#40;</span>Control ctrl<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Control c <span style="color: #0600FF;">in</span> ctrl.<span style="color: #0000FF;">Controls</span><span style="color: #000000;">&#41;</span>
&nbsp;
Register<span style="color: #000000;">&#40;</span>c<span style="color: #000000;">&#41;</span>;
&nbsp;
Page.<span style="color: #0000FF;">ClientScript</span>.<span style="color: #0000FF;">RegisterForEventValidation</span><span style="color: #000000;">&#40;</span>ctrl.<span style="color: #0000FF;">UniqueID</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/invalid-postback-or-call-argument/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Enums with description in c#</title>
		<link>http://fransiscuss.com/enums-with-description-in-c/</link>
		<comments>http://fransiscuss.com/enums-with-description-in-c/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 22:34:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=119</guid>
		<description><![CDATA[Sometime when we have Enum , we want to use it /bind it on the list as well with a better description/ word. With this method you can bind enum to a list which display its description but store its value as well.This is very useful function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Reflection;
using System.ComponentModel; 
&#160;
public class [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime when we have Enum , we want to use it /bind it on the list as well with a better description/ word. With this method you can bind enum to a list which display its description but store its value as well.This is very useful function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Xml</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Reflection</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span>; 
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Enums
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080;">#region helpers</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetEnumDescription<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Enum</span> value<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            FieldInfo fi <span style="color: #008000;">=</span> value.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetField</span><span style="color: #000000;">&#40;</span>value.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            DescriptionAttribute<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> attributes <span style="color: #008000;">=</span>
              <span style="color: #000000;">&#40;</span>DescriptionAttribute<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>fi.<span style="color: #0000FF;">GetCustomAttributes</span>
              <span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>DescriptionAttribute<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>attributes.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> 0<span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> attributes<span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Description</span> <span style="color: #008000;">:</span> value.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> T Parse<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> input<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #FF0000;">Enum</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span>, input<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region enums</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> ResultsType
        <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Featured Products&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            FeaturedProducts,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;New Products&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            NewStock,
            CategoryResults,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Specials&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            Specials,
            Brand,
            Row1,
            Row2,
            Row3,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;This Weeks Specials&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            ThisWeeksSpecials,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Top 10 Best Sellers&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            Top10BestSellers,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Special Offers&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            SpecialOffers,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Buy 1 Get 1 Free&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            Buy1Get1Free,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Half Price Bargains&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            HalfPriceBargains,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Top Sellers&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            TopSellers,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Summer Specials&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            SummerSpecials,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CUSTOMERS WHO BOUGHT THIS ALSO BOUGHT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            AlsoBought,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Related Products&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            Upsell
        <span style="color: #000000;">&#125;</span>
&nbsp;
          <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> ReportType
         <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Monthly Sales Report&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            MonthySalesReport <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Dispatched Orders Report&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            DispatchedOrdersReport <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
            <span style="color: #000000;">&#91;</span>Description<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Order Report&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
            OrderReport <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>
         <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>This is how you bind it</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> PopulateReportType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        ddlReportType.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        ddlReportType.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">New</span> ListItem<span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">GetEnumDescription</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">MonthySalesReport</span><span style="color: #000000;">&#41;</span>, Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">MonthySalesReport</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        ddlReportType.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">New</span> ListItem<span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">GetEnumDescription</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">DispatchedOrdersReport</span><span style="color: #000000;">&#41;</span>, Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">DispatchedOrdersReport</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        ddlReportType.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">New</span> ListItem<span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">GetEnumDescription</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">OrderReport</span><span style="color: #000000;">&#41;</span>, Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>Enums.<span style="color: #0000FF;">ReportType</span>.<span style="color: #0000FF;">OrderReport</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/enums-with-description-in-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Raise Event in User Control</title>
		<link>http://fransiscuss.com/raise-event-in-user-control/</link>
		<comments>http://fransiscuss.com/raise-event-in-user-control/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 22:31:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=117</guid>
		<description><![CDATA[I need to create a payment gateway user control that will be used accross all of the modules. This user control should be as simple as doing the transaction ONLY. So what I need to do is to let the host/page container knows whether the transaction is succeeded or not, if it is succeeded then [...]]]></description>
			<content:encoded><![CDATA[<p>I need to create a payment gateway user control that will be used accross all of the modules. This user control should be as simple as doing the transaction ONLY. So what I need to do is to let the host/page container knows whether the transaction is succeeded or not, if it is succeeded then the rest of the logic will be handled on ASPX page. </p>
<p>In order to do so I need to create an event on the user control that will be bubbled up to the page container/host. This sample might not be the best solution but it works perfectly for my needs and only requires several lines of code.</p>
<p><strong>Write this in your user control including declaration(signature) of parameter that you want to pass </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">Partial <span style="color: #0600FF;">Class</span> usercontrols_MyPaymentGateway
    <span style="color: #0600FF;">Inherits</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">UserControl</span>
&nbsp;
#Region <span style="color: #808080;">&quot;Property&quot;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">''' &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">''' this is an event for process status</span>
    <span style="color: #008080; font-style: italic;">''' &lt;/summary&gt;</span>
    <span style="color: #008080; font-style: italic;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Event</span> getProcessStatus<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> isPaid <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><strong>Write this in your user control where you want to raise the event and pass the parameter</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">     <span style="color: #0600FF;">RaiseEvent</span> getProcessStatus<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><strong>Write this in your page container<i>(Create an Event handler to handle your user control events) (NOTE: paymentGateway is the name of your user control)</i></strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;"> <span style="color: #008080; font-style: italic;">''' &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">''' event handler to the payment gateway controls</span>
    <span style="color: #008080; font-style: italic;">''' &lt;/summary&gt;</span>
    <span style="color: #008080; font-style: italic;">''' &lt;param name=&quot;isPaid&quot;&gt;&lt;/param&gt;</span>
    <span style="color: #008080; font-style: italic;">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> paymentProcessed<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> isPaid <span style="color: #FF8000;">as</span> <span style="color: #FF0000;">boolean</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> paymentGateway.<span style="color: #0000FF;">getProcessStatus</span>
&nbsp;
        <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>paymentGateway.<span style="color: #0000FF;">IsPaid</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            ltMessage.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Payment Successful &quot;</span> <span style="color: #008000;">+</span> paymentGateway.<span style="color: #0000FF;">ResponseMessage</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'if it is paid then we need to clear the remaining text boxes</span>
            paymentGateway.<span style="color: #0000FF;">ClearFields</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            ltMessage.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Payment Failed &quot;</span> <span style="color: #008000;">+</span> paymentGateway.<span style="color: #0000FF;">ResponseMessage</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/raise-event-in-user-control/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reference to user control in web.config</title>
		<link>http://fransiscuss.com/112/</link>
		<comments>http://fransiscuss.com/112/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 22:16:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[web.config]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=112</guid>
		<description><![CDATA[I&#8217;ve seen that most of people put their user control declaration in individual aspx page, and they declare it on the top of that page. What will happen if you are going to use it on multiple number of pages and i believe most of you would like to have a kind of tag that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen that most of people put their user control declaration in individual aspx page, and they declare it on the top of that page. What will happen if you are going to use it on multiple number of pages and i believe most of you would like to have a kind of tag that you can simply use on your web page to add your user control. In here, we declare all the user controls in web.config which I believe is more clean and manageable.</p>
<p><strong>Web.Config</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>pages validateRequest <span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>controls<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>add <span style="color: #0600FF;">namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;System.Web.UI&quot;</span> tagPrefix<span style="color: #008000;">=</span><span style="color: #666666;">&quot;asp&quot;</span> assembly<span style="color: #008000;">=</span><span style="color: #666666;">&quot;System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add tagPrefix<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MyControl&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/MyInternet/usercontrols/paymentgateway.ascx&quot;</span>			tagName<span style="color: #008000;">=</span><span style="color: #666666;">&quot;PaymentGateway&quot;</span> <span style="color: #008000;">/&gt;</span>
	  <span style="color: #008000;">&lt;/</span>controls<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>pages<span style="color: #008000;">&gt;</span>
	  <span style="color: #008000;">&lt;</span>httpModules<span style="color: #008000;">&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebPageSecurity&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Ventaur.Web.Security.SecureWebPageModule, WebPageSecurity&quot;</span> <span style="color: #008000;">/&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;RadUploadModule&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Telerik.WebControls.RadUploadHttpModule, RadUpload.Net2&quot;</span> <span style="color: #008000;">/&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;UrlRewriteModule&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter&quot;</span> <span style="color: #008000;">/&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebClientAuthorizationModule&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.Practices.CompositeWeb.Authorization.WebClientAuthorizationModule, Microsoft.Practices.CompositeWeb&quot;</span> <span style="color: #008000;">/&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ExceptionLoggerHttpModule&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.Practices.CompositeWeb.EnterpriseLibrary.ExceptionLogger, Microsoft.Practices.CompositeWeb.EnterpriseLibrary&quot;</span> <span style="color: #008000;">/&gt;</span>
		  <span style="color: #008000;">&lt;</span>add name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ScriptModule&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>httpModules<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p><strong>How to use it in ASPX Page</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;VB&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> CodeFile<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Checkout-Confirm.aspx.vb&quot;</span>
    Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;PaymentTest_Checkout_Confirm&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;!</span>DOCTYPE html <span style="color: #0600FF;">PUBLIC</span> <span style="color: #666666;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #666666;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;</span>Untitled Page<span style="color: #008000;">&lt;/</span>title<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>MyControl<span style="color: #008000;">:</span>PaymentGateway ID <span style="color: #008000;">=</span><span style="color: #666666;">&quot;ucpaymentgateway&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/112/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Find a control in ContentPlaceHolder</title>
		<link>http://fransiscuss.com/find-a-control-in-contentplaceholder/</link>
		<comments>http://fransiscuss.com/find-a-control-in-contentplaceholder/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 07:36:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[VB.NET]]></category>

		<category><![CDATA[Master Page]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=100</guid>
		<description><![CDATA[I have a user control and I would like to hide a control on the page container that host this user control. I try to use

1
Page.FindControl&#40;&#34;litContent&#34;&#41;

But It throws an error of object not found. The solution is you need to find the contentplaceholder first on the master page then you find the control that you [...]]]></description>
			<content:encoded><![CDATA[<p>I have a user control and I would like to hide a control on the page container that host this user control. I try to use</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">Page.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;litContent&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>But It throws an error of <strong>object not found</strong>. The solution is you need to find the contentplaceholder first on the master page then you find the control that you want from that placeholder. It&#8217;s a bit tricky since i thought once you get a Page instance then you can get all control hosted on the Page instance itself.</p>
<p>1. Place this tag on your asp.net page where it hosts your control</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;">&lt;%@ MasterType <span style="color: #0600FF;">TypeName</span><span style="color: #008000;">=</span><span style="color: #808080;">&quot;APL3_masterpages_home&quot;</span> %&gt;</pre></td></tr></table></div>

<p>2. go to the page behind of the user control/page where you want to place your logic to hide/show it</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="vbnet vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'hide the dynamic page from the parent page                    </span>
<span style="color: #0600FF;">Dim</span> mainContent <span style="color: #FF8000;">As</span> ContentPlaceHolder <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">Master</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;ContentPlaceHolder1&quot;</span><span style="color: #000000;">&#41;</span>, ContentPlaceHolder<span style="color: #000000;">&#41;</span>                     
&nbsp;
<span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #000000;">&#40;</span>mainContent <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>                        
   <span style="color: #0600FF;">Dim</span> contentPlaceHolder <span style="color: #FF8000;">As</span> Literal <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span>mainContent.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;litContent&quot;</span><span style="color: #000000;">&#41;</span>,Literal<span style="color: #000000;">&#41;</span>                         
   <span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #000000;">&#40;</span>contentPlaceHolder <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>                            
       contentPlaceHolder.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>                        
   <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span> 
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/find-a-control-in-contentplaceholder/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
