<?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>Tue, 17 Aug 2010 05:28:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Enter button in TextBox ASP.NET</title>
		<link>http://fransiscuss.com/enter-button-in-textbox-aspnet/</link>
		<comments>http://fransiscuss.com/enter-button-in-textbox-aspnet/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 05:28:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

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

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

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

		<guid isPermaLink="false">http://fransiscuss.com/?p=276</guid>
		<description><![CDATA[This article is demonstrating how to wire up an enter key into a textbox. For example you have a search text box where you press enter then it will click go button and at the same page you have another textbox where you want to do another button click when you press the enter which [...]]]></description>
			<content:encoded><![CDATA[<p>This article is demonstrating how to wire up an enter key into a textbox. For example you have a search text box where you press enter then it will click go button and at the same page you have another textbox where you want to do another button click when you press the enter which means it&#8217; is not necessary to post the page. This java script is used to capture the key event of enter and execute the LinkButton and ASP.NET button Click Event on the server side. Please add this javascript to your javascript common library or add this to your master page. This piece of code works in Firefox as well</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ButtonKeyPress<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">,</span> thisElementName<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">which</span> || evt.<span style="color: #660066;">keyCode</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> || <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// alert('post back href: ' +document.getElementById(thisElementName).href);</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                location <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">href</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>thisElementName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And add this to your .NET code behind on the page load</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> Protected <span style="color: #b1b100;">Sub</span> Page_Load<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">EventArgs</span><span style="color: #66cc66;">&#41;</span> Handles <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">Load</span>
         <span style="color: #b1b100;">If</span> <span style="color: #b1b100;">Not</span> Page.<span style="color: #66cc66;">IsPostBack</span> <span style="color: #b1b100;">Then</span>
&nbsp;
&nbsp;
            <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>User.<span style="color: #66cc66;">Identity</span>.<span style="color: #66cc66;">IsAuthenticated</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                Response.<span style="color: #66cc66;">Redirect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;frmTimeMain.aspx&quot;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
            txtGUID.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onkeydown&quot;</span>, <span style="color: #ff0000;">&quot;ButtonKeyPress(event, '&quot;</span> + lnkSubmit.<span style="color: #66cc66;">ClientID</span> + <span style="color: #ff0000;">&quot;')&quot;</span><span style="color: #66cc66;">&#41;</span>
            txtPassword.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onkeydown&quot;</span>, <span style="color: #ff0000;">&quot;ButtonKeyPress(event, '&quot;</span> + lnkSubmit.<span style="color: #66cc66;">ClientID</span> + <span style="color: #ff0000;">&quot;')&quot;</span><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;">Sub</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/enter-button-in-textbox-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET Calendar selected day on click method</title>
		<link>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/</link>
		<comments>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 05:17:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

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

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

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

		<category><![CDATA[Calendar javascript]]></category>

		<category><![CDATA[Calendar Selected Date]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=274</guid>
		<description><![CDATA[I&#8217;ve a case where I have an ASP.NET calendar that has a page load method that automatically select a date when it&#8217;s loaded. I also have an event defined for Selected_Changed which will be triggered only when the user select any other date other than pre-selected date on the load

Private Sub ctlCalendar_SelectionChanged&#40;ByVal sender As Object, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve a case where I have an ASP.NET calendar that has a page load method that automatically select a date when it&#8217;s loaded. I also have an event defined for Selected_Changed which will be triggered only when the user select any other date other than pre-selected date on the load</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ctlCalendar_SelectionChanged<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">EventArgs</span><span style="color: #66cc66;">&#41;</span> Handles ctlCalendar.<span style="color: #66cc66;">SelectionChanged</span>
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">Not</span> <span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">IsNullOrEmpty</span><span style="color: #66cc66;">&#40;</span>CalendarPreviousPage<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            BaseCalendar.<span style="color: #66cc66;">SelectedDate</span> = ctlCalendar.<span style="color: #66cc66;">SelectedDate</span>
            Response.<span style="color: #66cc66;">Redirect</span><span style="color: #66cc66;">&#40;</span>CalendarPreviousPage<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;">Sub</span></pre></div></div>

<p>But how do I wire up an event or when the selecteddate being clicked?You can use DayRender event and attach it to a javascript in this case I want to go back to previous page. BaseCalendar.Selected date can be any date where you want to set up/wire up the logic</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;"> <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ctlCalendar_DayRender<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Web</span>.<span style="color: #66cc66;">UI</span>.<span style="color: #66cc66;">WebControls</span>.<span style="color: #66cc66;">DayRenderEventArgs</span><span style="color: #66cc66;">&#41;</span> Handles ctlCalendar.<span style="color: #66cc66;">DayRender</span>
        <span style="color: #b1b100;">Dim</span> d <span style="color: #b1b100;">As</span> CalendarDay
        <span style="color: #b1b100;">Dim</span> c <span style="color: #b1b100;">As</span> TableCell
        d = e.<span style="color: #b1b100;">Day</span>
        c = e.<span style="color: #66cc66;">Cell</span>
&nbsp;
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>BaseCalendar.<span style="color: #66cc66;">SelectedDate</span>.<span style="color: #66cc66;">Value</span> = d.<span style="color: #b1b100;">Date</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            c.<span style="color: #66cc66;">Attributes</span>.<span style="color: #66cc66;">Add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;OnClick&quot;</span>, <span style="color: #ff0000;">&quot;history.go(-1)&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/aspnet-calendar-selected-day-on-click-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Telerik SL Gridview Cell Foreground color dynamically based on multiple binding</title>
		<link>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/</link>
		<comments>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 03:25:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

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

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

		<category><![CDATA[Cell Converter]]></category>

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

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

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

		<guid isPermaLink="false">http://fransiscuss.com/?p=256</guid>
		<description><![CDATA[I had a problem before where I build dynamic system (light dataset) for doing CRUD (Create, Read, Update and Delete) and I need to store the history of previous record before Update/Delete and at the same time I also need to indicate the column(e.g changing the color of the column) that has been changed per [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem before where I build dynamic system (light dataset) for doing CRUD (Create, Read, Update and Delete) and I need to store the history of previous record before Update/Delete and at the same time I also need to indicate the column(e.g changing the color of the column) that has been changed per record in history table. I&#8217;ve been struggling for a day in order to accomplish this.</p>
<p>1. You need to add reference and import System.Windows.Interactivity from SL3 SDK<br />
2. Create a TableHistoryColorConverter.vb</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>
Imports System.<span style="color: #66cc66;">Globalization</span>
Imports System.<span style="color: #66cc66;">Reflection</span>
&nbsp;
<span style="color: #b1b100;">Public</span> Class TableHistoryColorConverter
    <span style="color: #b1b100;">Implements</span> IValueConverter
&nbsp;
    <span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Function</span> Convert<span style="color: #66cc66;">&#40;</span>ByVal value <span style="color: #b1b100;">As</span> Object, ByVal targetType <span style="color: #b1b100;">As</span> System.<span style="color: #b1b100;">Type</span>, ByVal parameter <span style="color: #b1b100;">As</span> Object, ByVal culture <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Globalization</span>.<span style="color: #66cc66;">CultureInfo</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Object <span style="color: #b1b100;">Implements</span> System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>.<span style="color: #66cc66;">IValueConverter</span>.<span style="color: #66cc66;">Convert</span>
        <span style="color: #b1b100;">Dim</span> cellColor <span style="color: #b1b100;">As</span> SolidColorBrush = <span style="color: #b1b100;">New</span> SolidColorBrush<span style="color: #66cc66;">&#40;</span>Colors.<span style="color: #66cc66;">Black</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        Try
&nbsp;
            <span style="color: #b1b100;">Dim</span> columnList <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = value.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">Dim</span> currentColumnName <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = parameter.<span style="color: #66cc66;">ToString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #808080;">'Dim changeColumnParam As String = parameter.ToString()</span>
            <span style="color: #b1b100;">Dim</span> changedColumnList <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> = columnList.<span style="color: #b1b100;">Split</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">New</span> Char<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;,&quot;</span>c<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
            <span style="color: #b1b100;">If</span> changedColumnList.<span style="color: #66cc66;">Contains</span><span style="color: #66cc66;">&#40;</span>currentColumnName<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
                cellColor = <span style="color: #b1b100;">New</span> SolidColorBrush<span style="color: #66cc66;">&#40;</span>Colors.<span style="color: #66cc66;">Red</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
        Catch ex <span style="color: #b1b100;">As</span> Exception
&nbsp;
        <span style="color: #b1b100;">End</span> Try
&nbsp;
        <span style="color: #b1b100;">Return</span> cellColor
    <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> ConvertBack<span style="color: #66cc66;">&#40;</span>ByVal value <span style="color: #b1b100;">As</span> Object, ByVal targetType <span style="color: #b1b100;">As</span> System.<span style="color: #b1b100;">Type</span>, ByVal parameter <span style="color: #b1b100;">As</span> Object, ByVal culture <span style="color: #b1b100;">As</span> System.<span style="color: #66cc66;">Globalization</span>.<span style="color: #66cc66;">CultureInfo</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">As</span> Object <span style="color: #b1b100;">Implements</span> System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>.<span style="color: #66cc66;">IValueConverter</span>.<span style="color: #66cc66;">ConvertBack</span>
        Throw <span style="color: #b1b100;">New</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Not Implemented&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span>
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p>3. Create a vb class file called HistoryRecordFormatting.vb</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #b1b100;">Input</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Media</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Media</span>.<span style="color: #66cc66;">Animation</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Shapes</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Interactivity</span>
Imports Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>
Imports Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>
Imports System.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Data</span>
Imports SLCoreLib
&nbsp;
<span style="color: #b1b100;">Public</span> Class HistoryRecordFormatting
    Inherits Behavior<span style="color: #66cc66;">&#40;</span>Of RadGridView<span style="color: #66cc66;">&#41;</span>
&nbsp;
    Protected Overrides <span style="color: #b1b100;">Sub</span> OnAttached<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        MyBase.<span style="color: #66cc66;">OnAttached</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        AddHandler AssociatedObject.<span style="color: #66cc66;">RowLoaded</span>, <span style="color: #b1b100;">New</span> EventHandler<span style="color: #66cc66;">&#40;</span>Of Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>.<span style="color: #66cc66;">RowLoadedEventArgs</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>AddressOf AssociatedObject_RowLoaded<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
&nbsp;
    <span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> AssociatedObject_RowLoaded<span style="color: #66cc66;">&#40;</span>ByVal sender <span style="color: #b1b100;">As</span> Object, ByVal e <span style="color: #b1b100;">As</span> Telerik.<span style="color: #66cc66;">Windows</span>.<span style="color: #66cc66;">Controls</span>.<span style="color: #66cc66;">GridView</span>.<span style="color: #66cc66;">RowLoadedEventArgs</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">If</span> <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewHeaderRow<span style="color: #66cc66;">&#41;</span> OrElse <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewFooterRow<span style="color: #66cc66;">&#41;</span> OrElse <span style="color: #66cc66;">&#40;</span>TypeOf e.<span style="color: #66cc66;">Row</span> Is GridViewNewRow<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span>
            <span style="color: #b1b100;">Return</span>
        <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
&nbsp;
&nbsp;
        <span style="color: #b1b100;">For</span> Each cell In e.<span style="color: #66cc66;">Row</span>.<span style="color: #66cc66;">Cells</span>
            <span style="color: #808080;">'we want to apply logic to data rows only</span>
            <span style="color: #808080;">'ChangedColumns is the list of the column that has been edited (comma separated value) for that history record</span>
            <span style="color: #b1b100;">Dim</span> colorBinding <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">New</span> Binding<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ChangedColumns&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">With</span> <span style="color: #66cc66;">&#123;</span> _
                .<span style="color: #66cc66;">Converter</span> = <span style="color: #b1b100;">New</span> TableHistoryColorConverter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, .<span style="color: #66cc66;">ConverterParameter</span> = cell.<span style="color: #66cc66;">Column</span>.<span style="color: #66cc66;">UniqueName</span> _
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            cell.<span style="color: #66cc66;">SetBinding</span><span style="color: #66cc66;">&#40;</span>GridViewCell.<span style="color: #66cc66;">ForegroundProperty</span>, colorBinding<span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">Next</span>
        <span style="color: #808080;">'e.Row.Cells(1).SetBinding(GridViewCell.ForegroundProperty, colorBinding)</span>
        <span style="color: #808080;">'e.Row.Cells[1].SetBinding(GridViewCell.BackgroundProperty, colorBinding);	    </span>
    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span>
<span style="color: #b1b100;">End</span> Class</pre></div></div>

<p>4. Add behavior in your XAML (Interaction.Behaviors) tag and HistoryRecordFormatting.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;SLCommonControls:PopUpBase x:Class=&quot;iReferenceSL.frmRFHistory&quot;
xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; 
xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; 
xmlns:SLCommonControls=&quot;clr-namespace:SLCommonControls;assembly=SLCommonControls&quot; 
xmlns:controls=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls&quot;
xmlns:telerik=&quot;clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls&quot;
xmlns:telerikGrid=&quot;clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView&quot;
xmlns:telerikData=&quot;clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data&quot;
xmlns:dxm=&quot;clr-namespace:DevExpress.AgMenu;assembly=DevExpress.AgMenu.v8.2&quot;
xmlns:SLCoreConverter=&quot;clr-namespace:SLCoreLib;assembly=SLCoreLib&quot;
xmlns:local=&quot;clr-namespace:iReferenceSL&quot;
xmlns:i=&quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&quot;
Width=&quot;1000&quot; Height=&quot;800&quot; Title=&quot;History&quot;&gt;
    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;dxm:AgPopupMenu x:Name=&quot;ContextMenuTable&quot; PopupAnimationType=&quot;Scroll&quot;&gt;
            &lt;dxm:AgMenuItem  x:Name=&quot;mnuExport&quot; Header=&quot;Export&quot;&gt;
                &lt;dxm:AgMenuItem.Icon&gt;
                    &lt;Image Source=&quot;Images/Excel.png&quot; Width=&quot;16&quot; Height=&quot;16&quot;/&gt;
                &lt;/dxm:AgMenuItem.Icon&gt;
            &lt;/dxm:AgMenuItem&gt;
        &lt;/dxm:AgPopupMenu&gt;
        &lt;Grid.Resources&gt;
            &lt;SLCoreConverter:TableHistoryColorConverter x:Key=&quot;historyConverter&quot;&gt;&lt;/SLCoreConverter:TableHistoryColorConverter&gt;
        &lt;/Grid.Resources&gt;
        &lt;telerikGrid:RadGridView x:Name=&quot;dgResults&quot; Grid.Row=&quot;1&quot; 
        Grid.Column=&quot;0&quot; AutoGenerateColumns=&quot;False&quot; Exporting=&quot;ExportResults_Exporting&quot;&gt;
            &lt;i:Interaction.Behaviors&gt;
                &lt;local:HistoryRecordFormatting/&gt;
            &lt;/i:Interaction.Behaviors&gt;
        &lt;/telerikGrid:RadGridView&gt;
    &lt;/Grid&gt;
&lt;/SLCommonControls:PopUpBase&gt;</pre></div></div>

<p>Basically what it does is adding the converter on every single cell and use the column name to compare with the changed column. It uses Column.UniqueName to pass it to the ConverterParameter and check whether it&#8217;s on the list of changed column or not. The problem looks simple at the beginning but when it comes to silverlight then it&#8217;s different mechanism of applying the format compared with ASP.NET</p>
<p>The behavior and AssociatedObject_RowLoaded for me looks like itemdatabound event on repeater.</p>
]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/telerik-sl-gridview-cell-foreground-color-dynamically-based-on-multiple-binding/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reflection GetProperty case sensitive issue</title>
		<link>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/</link>
		<comments>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:49:25 +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[Case Sensitive]]></category>

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

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

		<guid isPermaLink="false">http://fransiscuss.com/?p=252</guid>
		<description><![CDATA[Reflection on .NET by default is case sensitive for the class member. To make it case insensitive you need to pass BindingFlags.IgnoreCase  . I&#8217;ve passed the ignorecase flag and now it doesn&#8217;t return anything!!!

&#160;
 Dim pi As PropertyInfo = Me.&#91;GetType&#93;&#40;&#41;.GetProperty&#40;fieldname, BindingFlags.IgnoreCase&#41;

Basically, if you pass one flag then the other flags will be overwritten by [...]]]></description>
			<content:encoded><![CDATA[<p>Reflection on .NET by default is case sensitive for the class member. To make it case insensitive you need to pass <em><strong>BindingFlags.IgnoreCase </strong></em> . I&#8217;ve passed the ignorecase flag and now it doesn&#8217;t return anything!!!</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">&nbsp;
 <span style="color: #b1b100;">Dim</span> pi <span style="color: #b1b100;">As</span> PropertyInfo = <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">&#91;</span>GetType<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">GetProperty</span><span style="color: #66cc66;">&#40;</span>fieldname, BindingFlags.<span style="color: #66cc66;">IgnoreCase</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Basically, if you pass one flag then the other flags will be overwritten by default which means all the default flags are disappeared. So to make it case insensitive then you need to pass other binding flags</p>

<div class="wp_syntax"><div class="code"><pre class="vb vb" style="font-family:monospace;">&nbsp;
 <span style="color: #b1b100;">Dim</span> pi <span style="color: #b1b100;">As</span> PropertyInfo = <span style="color: #b1b100;">Me</span>.<span style="color: #66cc66;">&#91;</span>GetType<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #66cc66;">GetProperty</span><span style="color: #66cc66;">&#40;</span>fieldname, BindingFlags.<span style="color: #66cc66;">IgnoreCase</span> <span style="color: #b1b100;">Or</span> BindingFlags.<span style="color: #b1b100;">Public</span> <span style="color: #b1b100;">Or</span> BindingFlags.<span style="color: #66cc66;">Instance</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/reflection-getproperty-case-sensitive-issue/feed/</wfw:commentRss>
		</item>
		<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>
	</channel>
</rss>
