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

<channel>
	<title>電腦茶包 Blog &#187; 程式設計</title>
	<atom:link href="http://www.minitw.com/archives/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.minitw.com</link>
	<description>解決資訊問題分享，電腦隨手筆記</description>
	<lastBuildDate>Sun, 29 Jan 2012 10:24:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>在.NET上實作SHA加密</title>
		<link>http://www.minitw.com/archives/751</link>
		<comments>http://www.minitw.com/archives/751#comments</comments>
		<pubDate>Mon, 19 Sep 2011 01:28:34 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SHA]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=751</guid>
		<description><![CDATA[SHA加密有很多種版本

下面用一個Function來實作.NET中所有的SHA加密]]></description>
			<content:encoded><![CDATA[<p>SHA加密有很多種版本，像是SHA1、SHA256....等</p>
<p>下面用一個Function來實作.NET中所有的SHA加密</p>
<pre class="brush: csharp; title: ;">
using System;
using System.Security.Cryptography;
using System.Text;

namespace SystemAPI.Function.EncryptLibrary
{
    public class EncryptSHA
    {
        /// &lt;summary&gt;
        /// 使用SHA加密訊息
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;sourceMessage&quot;&gt;原始資訊&lt;/param&gt;
        /// &lt;param name=&quot;SHAType&quot;&gt;SHA加密方式&lt;/param&gt;
        /// &lt;returns&gt;string&lt;/returns&gt;
        public string Encrypt(string sourceMessage, EnumSHAType SHAType)
        {
            if (string.IsNullOrEmpty(sourceMessage))
            {
                return string.Empty;
            }

            //字串先轉成byte[]
            byte[] Message = Encoding.Unicode.GetBytes(sourceMessage);
            HashAlgorithm HashImplement = null;

            //選擇要使用的SHA加密方式
            switch (SHAType)
            {
                case  EnumSHAType.SHA1:
                    HashImplement = new SHA1Managed();
                    break;
                case EnumSHAType.SHA256:
                    HashImplement = new SHA256Managed();
                    break;
                case EnumSHAType.SHA384:
                    HashImplement = new SHA384Managed();
                    break;
                case EnumSHAType.SHA512:
                    HashImplement = new SHA512Managed();
                    break;
            }

            //取Hash值
            byte[] HashValue = HashImplement.ComputeHash(Message);

            //把byte[]轉成string後，再回傳
            return BitConverter.ToString(HashValue).Replace(&quot;-&quot;,&quot;&quot;).ToLower();

        }

        public enum EnumSHAType
        {
            SHA1,
            SHA256,
            SHA384,
            SHA512
        }

    }
}
</pre>
<p>.<br />
使用方式如下：</p>
<pre class="brush: csharp; title: ;">
EncryptSHA SHA = new EncryptSHA();
string EncryptString = SHA.Encrypt(&quot;12345&quot;, EncryptSHA.EnumSHAType.SHA512);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/751/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle官方的 Linq to Oracle</title>
		<link>http://www.minitw.com/archives/721</link>
		<comments>http://www.minitw.com/archives/721#comments</comments>
		<pubDate>Fri, 08 Apr 2011 02:48:23 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[linq to oracle]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=721</guid>
		<description><![CDATA[這幾天無意間發現Oracle官方也支援Linq to Oracle了 雖然還是測試版，不過至少踏出了第一步了吶 下載的名稱為： 32-bit Oracle Data Access Components (ODAC) for Microsoft Entity Framework and LINQ to Entities  想嘗鮮的朋友可以先玩看看 參考資料： Tutorial. Entity Framework, LINQ and Model-First for the Oracle Database]]></description>
			<content:encoded><![CDATA[<p>這幾天無意間發現Oracle官方也支援Linq to Oracle了</p>
<p>雖然還是測試版，不過至少踏出了第一步了吶</p>
<p>下載的名稱為：<br />
<a href="http://www.oracle.com/technetwork/topics/dotnet/downloads/oracleefbeta-302521.html" target="_blank">32-bit Oracle Data Access Components (ODAC)<br />
for Microsoft Entity Framework and LINQ to Entities </a></p>
<p>想嘗鮮的朋友可以先玩看看</p>
<p>參考資料：<br />
<a href="http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/EntityFrameworkOBE/EntityFrameworkOBE.htm" target="_blank">Tutorial. Entity Framework, LINQ and Model-First for the Oracle Database</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/721/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在.Net中使用繼承建構子(Constructor)</title>
		<link>http://www.minitw.com/archives/707</link>
		<comments>http://www.minitw.com/archives/707#comments</comments>
		<pubDate>Mon, 21 Feb 2011 03:36:49 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Constructor]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[建構子]]></category>
		<category><![CDATA[繼承]]></category>
		<category><![CDATA[繼承建構子]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=707</guid>
		<description><![CDATA[繼承建構子(Constructor)，這看起來既有學問又深奧的文字。 

不要怕，以下我問白話文解釋一下。 

把繼承建構子分解後，就是 繼承 + 建構子。 

繼承，相信有物件導向概念的朋友應該都知道這2個字的意思。 

建構子(Constructor)，就是用來進行物件初始化的方法。 

一般來說，Class B 繼承 Class A 之後就可以使用Class A所開放出來的東西。 

那麼如果Class B 繼承 Class A後，想要對Class A進行初始化的動作，那就需要使用繼承建構子了。

先來看看程式吧，看程式就比較不會那麼文謅謅了。
]]></description>
			<content:encoded><![CDATA[<p>繼承建構子(Constructor)，這看起來既有學問又深奧的文字 </p>
<p>不要怕，以下我問白話文解釋一下 </p>
<p>把繼承建構子分解後，就是 繼承 + 建構子 </p>
<p>繼承，相信有物件導向概念的朋友應該都知道這2個字的意思 </p>
<p>建構子(Constructor)，就是用來進行物件初始化的方法 </p>
<p>一般來說，Class B 繼承 Class A 之後就可以使用Class A所開放出來的東西 </p>
<p>那麼如果Class B 繼承 Class A後，想要對Class A進行初始化的動作，那就需要使用繼承建構子了 </p>
<p>先來看看程式吧，看程式就比較不會那麼文謅謅了。程式碼可於這邊<a href="http://www.minitw.com/download/BaseSampleCode.zip" target="_self">下載</a>(C#、VB.NET雙版本)</p>
<p>首先有一個最基本的Class，我們叫它Class A </p>
<p>C#版本Class A </p>
<pre class="brush: csharp; title: ;">
class ClassA
{
    public ClassA()
    {
        _InitString = &quot;123&quot;;
    }

    public ClassA(string initStr)
    {
        _InitString = initStr;
    }

    private string _InitString;
    public string InitString
    {
        get { return _InitString; }
    }

    public void ShowClassAInit()
    {
        Console.WriteLine(InitString);
        Console.WriteLine(&quot;-----------------------------&quot;);
    }
}
</pre>
<p>VB.NET版本Class A </p>
<pre class="brush: vb; title: ;">
Class ClassA
    Public Sub New()
        _InitString = &quot;123&quot;
    End Sub

    Public Sub New(ByVal initStr As String)
        _InitString = initStr
    End Sub

    Private _InitString As String
    Public ReadOnly Property InitString() As String
        Get
            Return _InitString
        End Get
    End Property

    Public Sub ShowClassAInit()
        Console.WriteLine(InitString)
        Console.WriteLine(&quot;-----------------------------&quot;)
    End Sub
End Class
</pre>
<p>接下來我們需要Class B來繼承Class A </p>
<p>注意到了嗎，繼承建構子的實作方式就是於Class B加入一個與Class A一樣的初始建構子</p>
<p>並使用base(C#語法)、MyBase.New(VB.NET語法)把初始值帶入Class A。成功於Class B內，進行初始化Class A的動作 </p>
<p>C#版本Class B </p>
<pre class="brush: csharp; title: ;">
class ClassB : ClassA
{
    public ClassB()
    {        
    }

    public ClassB(string initStr)
        : base(initStr)
    {           
    }        
}
</pre>
<p>VB.NET版本Class B </p>
<pre class="brush: vb; title: ;">
Class ClassB
    Inherits ClassA

    Public Sub New()
    End Sub

    Public Sub New(ByVal initStr As String)
        MyBase.New(initStr)
    End Sub

End Class
</pre>
<p>接下來就看看怎麼使用，跟使用的結果吧<br />
下面使用Console來DemoC#版本Console </p>
<pre class="brush: csharp; title: ;"> 

class Program
{
    static void Main(string[] args)
    {
        ClassA CA1 = new ClassA();
        Console.WriteLine(&quot;new ClassA()&quot;);
        CA1.ShowClassAInit(); //Result:123 

        ClassA CA2 = new ClassA(&quot;Init AAA&quot;);
        Console.WriteLine(&quot;new ClassA(\&quot;Init AAA\&quot;)&quot;);
        CA2.ShowClassAInit(); //Result:Init AAA 

        ClassB CB1 = new ClassB();
        Console.WriteLine(&quot;new ClassB()&quot;);
        CB1.ShowClassAInit(); //Result:123 

        ClassB CB2 = new ClassB(&quot;Init BBB&quot;);
        Console.WriteLine(&quot;new ClassB(\&quot;Init BBB\&quot;)&quot;);
        CB2.ShowClassAInit(); //Result:Init BBB 

        Console.ReadLine();
    }
} 
</pre>
<p>  </p>
<p>VB.NET版本Console </p>
<pre class="brush: vb; title: ;"> 

Module Module1 

    Sub Main()
        Dim CA1 As New ClassA()
        Console.WriteLine(&quot;new ClassA()&quot;)
        CA1.ShowClassAInit()  'Result:123 

        Dim CA2 As New ClassA(&quot;Init AAA&quot;)
        Console.WriteLine(&quot;new ClassA(&quot;&quot;Init AAA&quot;&quot;)&quot;)
        CA2.ShowClassAInit()  'Result:Init AAA 

        Dim CB1 As New ClassB
        Console.WriteLine(&quot;new ClassB()&quot;)
        CB1.ShowClassAInit()  'Result:123 

        Dim CB2 As New ClassB(&quot;Init BBB&quot;)
        Console.WriteLine(&quot;new ClassB(&quot;&quot;Init BBB&quot;&quot;)&quot;)
        CB2.ShowClassAInit()  'Result:Init BBB 

        Console.ReadLine() 

    End Sub 

End Module 
</pre>
<p>執行結果如下圖<br />
<a title="Flickr 20110221_1" href="http://www.flickr.com/photos/jokkson/5463835988/"><img src="http://farm6.static.flickr.com/5136/5463835988_6b7de189af.jpg" alt="20110221_1" width="349" height="311" /></a></p>
<p>以上程式碼可於這邊<a href="http://www.minitw.com/download/BaseSampleCode.zip" target="_self">下載</a>(C#、VB.NET雙版本)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/707/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET 的另類可斷行字串寫法</title>
		<link>http://www.minitw.com/archives/675</link>
		<comments>http://www.minitw.com/archives/675#comments</comments>
		<pubDate>Wed, 24 Nov 2010 12:13:05 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=675</guid>
		<description><![CDATA[有寫過C#的朋友大概都知道，要在C#中輸入一段有斷行的字串或SQL時，
都會使用「@」這個好用的符號。好處就是可以直接斷行。
如果行數一多，那可真是累死人不償命又無聊的工程。
某天在黑暗執行緒的某一篇文章挖到了寶，
使用VB.NET 2008內建的XML嵌入語法，來達成模擬C#的「@」。



]]></description>
			<content:encoded><![CDATA[<p>有寫過C#的朋友大概都知道，要在C#中輸入一段有斷行的字串或SQL時</p>
<p>都會使用「@」這個好用的符號。好處就是可以直接斷行</p>
<p>例如：<br />
string test = @"<br />
select * from tb<br />
where c1 = 123"</p>
<p>但是在VB.NET就要很鱉腳用 「 &amp; _ 」來斷行<br />
例如：<br />
dim test as string<br />
test = "select * from tb" &amp; _<br />
"where c1 = 123"</p>
<p>如果行數一多，那可真是累死人不償命又無聊的工程<br />
某天在<a href="http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/06/19/c-or-vb-net.aspx#6697">黑暗執行緒的某一篇文章</a>挖到了寶</p>
<p>使用VB.NET 2008內建的XML嵌入語法，來達成模擬C#的「@」<br />
直接看下面的例子</p>
<pre class="brush: vb; title: ;">
        Dim JS As String = &lt;s&gt;&lt;![CDATA[
                &lt;script type=&quot;text/javascript&quot;&gt;
                jQuery(function ($) {
                    $('#@txtbox.ClientID@').datepicker({
                    rangeSelect: true,
                    firstDay: 1,
                    changeMonth: true,
                    changeYear: true,
                    showOn: 'both',
                    buttonImageOnly: true,
                    buttonImage: '@Context.Request.ApplicationPath@/Picture/calendar.gif'
                    });
                });
                &lt;/script&gt;
        ]]&gt;&lt;/s&gt;.Value.Replace(vbLf, vbCrLf)</pre>
<p>跟據Ark網友的補充，由於預設的換行是vbLf，所以後面我加了Replace(vbLf, vbCrLf)<br />
來把換行符號變成vbCrLf</p>
<p>那如果字串裡面有變數怎麼辦?<br />
先把變數用@包起來，例如：@txtbox.ClientID@<br />
之後再用Replace去把變數塞進去，例如：JS = JS.Replace("@txtbox.ClientID@", "AAAA")</p>
<p>看來一切都很完美了，不過還沒結束<br />
當你在VS2010上使用時你會發現字串內的文字是接近白色的<br />
這對老人家的眼力是很大的考驗<br />
<a title="Flickr 上  20101124_1" href="http://www.flickr.com/photos/jokkson/5203520505/"><img src="http://farm5.static.flickr.com/4085/5203520505_c1563dbd76.jpg" alt="20101124_1" width="500" height="256" /></a></p>
<p>這時候可以進去選項裡面調整</p>
<p><a title="Flickr 上 的 20101124_2" href="http://www.flickr.com/photos/jokkson/5204119842/"><img src="http://farm6.static.flickr.com/5284/5204119842_c4fc8d6b65.jpg" alt="20101124_2" width="306" height="427" /></a></p>
<p>選擇字型與色形，再挑選VB XML CData 區段，調整你想要顏色，按下確定</p>
<p><a title="Flickr 上  的 20101124_3" href="http://www.flickr.com/photos/jokkson/5204119908/"><img src="http://farm5.static.flickr.com/4084/5204119908_743849e9b8.jpg" alt="20101124_3" width="500" height="276" /></a></p>
<p>收工</p>
<p><a title="Flickr 上  的 20101124_4" href="http://www.flickr.com/photos/jokkson/5204119954/"><img src="http://farm6.static.flickr.com/5046/5204119954_404d67a4f1.jpg" alt="20101124_4" width="500" height="262" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/675/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>讓.Net的方法、函式顯示過時</title>
		<link>http://www.minitw.com/archives/667</link>
		<comments>http://www.minitw.com/archives/667#comments</comments>
		<pubDate>Tue, 09 Nov 2010 05:28:16 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Obsolete]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[過時]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=667</guid>
		<description><![CDATA[如果你有寫公用程式讓使用者使用，也許經過版本的更新 有些方法、函式已經過時或過期了 你不再建議使用者繼續使用，而是改用新的方法 這時候要怎麼提示使用者呢? 答案就是使用 Obsolete 這個屬性 先來看看範例程式碼 VB.NET 的語法如下 Partial Public Class GetDirectoryFiles ''' &#60;summary&#62; ''' 取得資料夾與檔案 ''' &#60;/summary&#62; ''' &#60;returns&#62;String&#60;/returns&#62; ''' &#60;remarks&#62;&#60;/remarks&#62; &#60;Obsolete(&#34;這個方法已經過時了，建議使用新的方法GetDF()&#34;)&#62; _ Public Function GetDirectoryFile() As String Return &#34;&#34; End Function End Class C# 的語法如下 public partial class GetDirectoryFiles { /// &#60;summary&#62; /// 取得資料夾與檔案 /// &#60;/summary&#62; /// &#60;returns&#62;String&#60;/returns&#62; /// &#60;remarks&#62;&#60;/remarks&#62; [Obsolete(&#34;這個方法已經過時了，建議使用新的方法GetDF()&#34;)] [...]]]></description>
			<content:encoded><![CDATA[<p>如果你有寫公用程式讓使用者使用，也許經過版本的更新<br />
有些方法、函式已經過時或過期了<br />
你不再建議使用者繼續使用，而是改用新的方法<br />
這時候要怎麼提示使用者呢?</p>
<p>答案就是使用 Obsolete 這個屬性<br />
先來看看範例程式碼</p>
<p>VB.NET 的語法如下</p>
<pre class="brush: vb; title: ;">
    Partial Public Class GetDirectoryFiles
        ''' &lt;summary&gt;
        ''' 取得資料夾與檔案
        ''' &lt;/summary&gt;
        ''' &lt;returns&gt;String&lt;/returns&gt;
        ''' &lt;remarks&gt;&lt;/remarks&gt;
        &lt;Obsolete(&quot;這個方法已經過時了，建議使用新的方法GetDF()&quot;)&gt; _
        Public Function GetDirectoryFile() As String
            Return &quot;&quot;
        End Function
    End Class
</pre>
<p>C# 的語法如下</p>
<pre class="brush: csharp; title: ;">
public partial class GetDirectoryFiles
{
	/// &lt;summary&gt;
	/// 取得資料夾與檔案
	/// &lt;/summary&gt;
	/// &lt;returns&gt;String&lt;/returns&gt;
	/// &lt;remarks&gt;&lt;/remarks&gt;
	[Obsolete(&quot;這個方法已經過時了，建議使用新的方法GetDF()&quot;)]
	public string GetDirectoryFile()
	{
		return &quot;&quot;;
	}
}
</pre>
<p></p>
<p>當使用者使用到這個方法、函式就會出現下面的提示<br />
提示使用者需要注意一下<br />
<a href="http://www.flickr.com/photos/jokkson/5160008737/" title="Flickr 20101109_1"><img src="http://farm5.static.flickr.com/4107/5160008737_0980417eb7_z.jpg" width="640" height="69" alt="20101109_1" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/667/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解決DocProject External UI開啟專案時發生的錯誤</title>
		<link>http://www.minitw.com/archives/590</link>
		<comments>http://www.minitw.com/archives/590#comments</comments>
		<pubDate>Wed, 14 Apr 2010 07:20:24 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=590</guid>
		<description><![CDATA[DocProject 是一個在.NET下，可以幫你自動產生程式碼文件的東西。
如果你安裝完成後，使用Visual Studio 2008建立DocProject專案後，
此時可以接於Visual Studio內進行建置，並不會有錯誤。
但如果是用DocProject External UI來開啟專案你就會收到一個錯誤........]]></description>
			<content:encoded><![CDATA[<p>DocProject 是一個在.NET下，可以幫你自動產生程式碼文件的東西<br />
詳細的介紹可到<a href="http://davesexton.com/blog">作者網站</a>參考<br />
中文的資料可參考<a href="http://www.cnblogs.com/hwade/articles/885020.html">使用DocProject外速產生.NET物件文件(一) - 黃偉榮的學習筆記- 博客園</a></p>
<p>如果你安裝完成後，使用Visual Studio 2008建立DocProject專案後<br />
此時可以在Visual Studio內進行建置，並不會有錯誤<br />
但如果是用DocProject External UI來開啟專案你就會收到一個錯誤，像下圖<br />
這是因為程式找不到輸出的路徑<br />
<a title="20100414_1" href="http://www.flickr.com/photos/jokkson/4519629975/"><img src="http://farm3.static.flickr.com/2782/4519629975_dc778c4d9e.jpg" alt="20100414_1" /></a></p>
<p>解決方法如下：<br />
1.先使用記事本開啟DocProject的專案檔(csproj 或 vbproj)<br />
2.於第一個&lt;PropertyGroup&gt;內插入&lt;OutputPath&gt;bin\&lt;/OutputPath&gt;。如下圖所示</p>
<p><a title="20100414_2" href="http://www.flickr.com/photos/jokkson/4520265906/"><img src="http://farm3.static.flickr.com/2578/4520265906_1021d51b60.jpg" alt="20100414_2" /></a></p>
<p>接下來就可以順利使用DocProject External UI了<br />
建置時，別忘了選擇編譯的CPU類型<br />
<a title="20100414_3" href="http://www.flickr.com/photos/jokkson/4519630053/"><img src="http://farm3.static.flickr.com/2700/4519630053_f5f1410116.jpg" alt="20100414_3" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/590/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XDocument To XmlDocument</title>
		<link>http://www.minitw.com/archives/568</link>
		<comments>http://www.minitw.com/archives/568#comments</comments>
		<pubDate>Mon, 15 Mar 2010 10:34:47 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ to XML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=568</guid>
		<description><![CDATA[XDocument是Linq所提供的一個關於XML的類別。
但有的時候我們所使用的方法要求傳入的是XmlDocument。
但是在傳入之前，我們想要針對這個XML檔案做一些處理後，再傳進去。
這時候就可以利用XDocument，經由Linq處理後，再轉成XmlDocument丟進去。]]></description>
			<content:encoded><![CDATA[<p>XDocument是Linq所提供的一個關於XML的類別<br />
但有的時候我們所使用的方法要求傳入的是XmlDocument<br />
但是在傳入之前，我們想要針對這個XML檔案做一些處理後，再傳進去<br />
這時候就可以利用XDocument，經由Linq處理後，再轉成XmlDocument丟進去<br />
註：用了Linq to XML，終於可以離開之前寫XML相關處理的惡夢，Linq真是個好東西</p>
<p>話不多說了，直接來看程式吧</p>
<pre class="brush: csharp; title: ;">
using System.Xml.Linq;
XDocument XDoc = XDocument.Load(Log4NetConfigXMLFilePath);
var nodes = (from p in XDoc.Elements(&quot;log4net&quot;)
                  .Elements(&quot;appender&quot;)
                  .Elements(&quot;file&quot;)
             elect p).FirstOrDefault();
//使用Linq Select出來後，進行處理
nodes.SetAttributeValue(&quot;value&quot;,HttpContext.Current.Server.MapPath(&quot;~/&quot;) +
                                 nodes.Attribute(&quot;value&quot;).Value);
//轉出來後再放到XmlDocument
System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
//把XDocument轉成XmlDocument
XmlDoc.LoadXml(XDoc.Document.ToString());
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/568/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在ASP.NET中動態載入圖片</title>
		<link>http://www.minitw.com/archives/565</link>
		<comments>http://www.minitw.com/archives/565#comments</comments>
		<pubDate>Tue, 09 Mar 2010 06:24:58 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[ashx]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[動態載入]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=565</guid>
		<description><![CDATA[一般在ASP.NET中要載入圖片，都是要先把圖片存成檔案

然後把Image的Url指向圖片檔案

但是如果圖片的來源是資料庫的二進位值，或是由系統產生無實體圖片呢

解決方法就是使用泛型處理常式(ashx)]]></description>
			<content:encoded><![CDATA[<p>一般在ASP.NET中要載入圖片，都是要先把圖片存成檔案<br />
然後把Image的Url指向圖片檔案<br />
但是如果圖片的來源是資料庫的二進位值，或是由系統產生無實體圖片就無法這麼做了<br />
解決方法就是使用泛型處理常式(ashx)</p>
<p>首先新增一個泛型處理常式(ashx)<br />
<a title="20100309_1" href="http://www.flickr.com/photos/jokkson/4418585199/"><img src="http://farm5.static.flickr.com/4017/4418585199_c938262e4f.jpg" alt="20100309_1" width="500" height="286" /></a></p>
<p>然後把程式寫在裡面(程式碼請往下看)</p>
<p>最後把Image的Url位置指向我們新增的ashx檔的位置即可<br />
<a href="http://www.flickr.com/photos/jokkson/4418585223/" title="20100309_2"><img src="http://farm5.static.flickr.com/4035/4418585223_d975718269.jpg" width="304" height="344" alt="20100309_2" /></a></p>
<p>範例程式：測試程式的<a href="http://www.minitw.com/download/ashxShowImage.zip">專案檔</a></p>
<p>Default.aspx</p>
<pre class="brush: vb; title: ;">
        '把實體圖片讀成Byte
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim f As System.IO.FileStream
        f = System.IO.File.OpenRead(HttpContext.Current
                         .Server.MapPath(&quot;20100309_1.jpg&quot;))
        Dim b(f.Length) As Byte
        f.Read(b, 0, f.Length - 1)
        Session(&quot;pic&quot;) = b
    End Sub
</pre>
<p>Showlogo.ashx</p>
<pre class="brush: vb; title: ;">
Imports System.Web.SessionState

Public Class Showlogo
    Implements System.Web.IHttpHandler
    Implements IRequiresSessionState

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        Dim b() As Byte = context.Session(&quot;pic&quot;)

        context.Response.ContentType = &quot;text/jpg&quot;
        context.Response.BinaryWrite(b)

    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
</pre>
<p>參考資料：<br />
<a href="http://blog.miniasp.com/post/2008/03/Using-contextSession-object-in-HttpHandler.aspx">在 HttpHandler 中使用 Session 的注意事項 </a><br />
<br />
<a href="http://www.dotblogs.com.tw/puma/archive/2008/03/16/1682.aspx">利用 ASP.NET的泛型處理常式(Handler)產生圖片驗證碼,結合IRequiresSessionState將驗證碼儲存在session裡,透過 session值來驗證</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/565/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Oracle中直接使用Table名稱</title>
		<link>http://www.minitw.com/archives/562</link>
		<comments>http://www.minitw.com/archives/562#comments</comments>
		<pubDate>Mon, 08 Mar 2010 02:02:27 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=562</guid>
		<description><![CDATA[對於我這個Oracle新手而言，有太多東西要學了 一般在Oracle中要Select Table時，除了自已建的Table外 要Select其他人建的表格，就要像這樣子  Select * from 帳號.Table 如果要去掉這個限制，就使用下面這段語法 grant all on table_name to public; drop public synonym table_name;//第一次建立可省略 create public synonym table_name for table_name;]]></description>
			<content:encoded><![CDATA[<p>對於我這個Oracle新手而言，有太多東西要學了</p>
<p>一般在Oracle中要Select Table時，除了自已建的Table外</p>
<p>要Select其他人建的表格，就要像這樣子  Select * from 帳號.Table</p>
<p>如果要去掉這個限制，就使用下面這段語法</p>
<pre class="brush: sql; title: ;">
grant all on table_name to public;
drop   public synonym table_name;//第一次建立可省略
create public synonym table_name for table_name;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/562/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[轉錄]ASP.Net 事件發生先後順序</title>
		<link>http://www.minitw.com/archives/557</link>
		<comments>http://www.minitw.com/archives/557#comments</comments>
		<pubDate>Sun, 21 Feb 2010 14:45:45 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[好文轉錄]]></category>
		<category><![CDATA[程式設計]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=557</guid>
		<description><![CDATA[快被載入順序煩死了，幸好有好心人提供，以下為文章 資料來源網站：瓶水相逢.Net 一般情況下： Page.PreInit Page.Init Page.InitComplete Page.PreLoad Page.Load Page.LoadComplete Page.PreRender Page.PreRenderComplete 使用了 MasterPage 情況， MasterPage 與 ContentPage 事件順序： ContentPage.PreInit Master.Init ContentPage.Init ContentPage.InitComplete ContentPage.PreLoad ContentPage.Load Master.Load ContentPage.LoadComplete ContentPage.PreRender Master.PreRender ContentPage.PreRenderComplete 參考： (1) ASP.NET 網頁生命週期概觀 (2) ASP.NET 主版和內容頁面中的事件]]></description>
			<content:encoded><![CDATA[<p>快被載入順序煩死了，幸好有好心人提供，以下為文章</p>
<p>資料來源網站：<a href="http://www.dotblogs.com.tw/chhuang/archive/2008/03/18/1872.aspx" target="_blank">瓶水相逢.Net</a></p>
<ul>
<li>一般情況下：</li>
</ul>
<p>Page.PreInit<br />
Page.Init<br />
Page.InitComplete<br />
Page.PreLoad<br />
Page.Load<br />
Page.LoadComplete<br />
Page.PreRender<br />
Page.PreRenderComplete</p>
<ul>
<li>使用了 MasterPage 情況， MasterPage 與 ContentPage 事件順序：</li>
</ul>
<p>ContentPage.PreInit<br />
Master.Init<br />
ContentPage.Init<br />
ContentPage.InitComplete<br />
ContentPage.PreLoad<br />
ContentPage.Load<br />
Master.Load<br />
ContentPage.LoadComplete<br />
ContentPage.PreRender<br />
Master.PreRender<br />
ContentPage.PreRenderComplete</p>
<p>參考：<br />
(1) <a href="http://msdn2.microsoft.com/zh-tw/library/ms178472%28VS.80%29.aspx" target="_blank">ASP.NET  網頁生命週期概觀</a><br />
(2) <a href="http://msdn2.microsoft.com/zh-tw/library/dct97kc3%28VS.80%29.aspx" target="_blank">ASP.NET  主版和內容頁面中的事件</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/557/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP 與 ASP.Net Session 共用</title>
		<link>http://www.minitw.com/archives/541</link>
		<comments>http://www.minitw.com/archives/541#comments</comments>
		<pubDate>Fri, 25 Dec 2009 02:16:15 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[Share]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=541</guid>
		<description><![CDATA[要讓ASP與ASP.NET的Session可以共用的話，需要一些技巧 微軟官方作法是使用SQL Server當中介站，相關說明可參考這邊 不過考量到不是每個專案都會用到SQL Server，所以參考較為簡單的方式來解決 請參考Transfer Session Variables from Classic ASP to ASP.NET，範例網站內可下載。或由小站這邊下載 不過需注意的地方是，如果你要傳的資料很敏感，那請記得加密後再傳 且為了避免使用者攔劫資料修改，建議是加上檢查碼，或是加密 ASP.NET收到後再解密 相關網站： Session 共用與跨網域 Transfer Session Variables from Classic ASP to ASP.NET How to Share Session State Between Classic ASP and ASP.NET 解決ASP與ASP.NET共存於一專案Session共用問題(StateStitch)]]></description>
			<content:encoded><![CDATA[<p>要讓ASP與ASP.NET的Session可以共用的話，需要一些技巧</p>
<p>微軟官方作法是使用SQL Server當中介站，相關說明可參考<a href="http://www.eggheadcafe.com/articles/20021207.asp">這邊</a></p>
<p>不過考量到不是每個專案都會用到SQL Server，所以參考較為簡單的方式來解決</p>
<p>請參考<a href="http://www.eggheadcafe.com/articles/20021207.asp">Transfer Session Variables from Classic ASP to ASP.NET</a>，範例網站內可下載。或由小站這邊<a href="http://www.minitw.com/download/asp2aspnet.zip">下載</a></p>
<p>不過需注意的地方是，如果你要傳的資料很敏感，那請記得加密後再傳</p>
<p>且為了避免使用者攔劫資料修改，建議是加上檢查碼，或是加密</p>
<p>ASP.NET收到後再解密</p>
<p>相關網站：</p>
<p><a href="http://blog.xuite.net/sugopili/computerblog/16200058">Session 共用與跨網域</a></p>
<p><a href="http://www.eggheadcafe.com/articles/20021207.asp">Transfer Session Variables from Classic ASP to ASP.NET</a></p>
<p><a href="http://msdn2.microsoft.com/en-us/library/aa479313.aspx">How to Share Session State Between Classic ASP and ASP.NET</a></p>
<p><a href="http://www.dotblogs.com.tw/topcat/archive/2008/03/05/1216.aspx">解決ASP與ASP.NET共存於一專案Session共用問題(StateStitch)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/541/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用讀卡機取得自然人憑證的卡號</title>
		<link>http://www.minitw.com/archives/534</link>
		<comments>http://www.minitw.com/archives/534#comments</comments>
		<pubDate>Fri, 11 Dec 2009 08:55:44 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[卡號]]></category>
		<category><![CDATA[自然人憑證]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=534</guid>
		<description><![CDATA[上一篇文章取得Smart Card的APDU Command，說明如何側錄讀卡機的指令與回傳值 這篇文章將實作程式來讀取自然人憑證的卡號 程式參考於使用C#讀取自然人評證卡號 但實作後仍無法正確顯示，所以使用 WinSCard APDU View Utility 來側錄指令後，修改成下面的程式碼 Imports System Imports System.Text Imports System.Runtime.InteropServices Public Class DigitalCard Private Structure SCARD_IO_REQUEST Public dwProtocol As Integer Public cbPciLength As Integer End Structure '引用 PC/SC(Personal Computer/Smart Card) API WinScard.dll &#60;DllImport(&#34;WinScard.dll&#34;)&#62; _ Private Shared Function SCardEstablishContext(ByVal dwScope As UInteger, ByVal nNotUsed1 As Integer, ByVal nNotUsed2 As [...]]]></description>
			<content:encoded><![CDATA[<p>上一篇文章<a href="http://www.minitw.com/archives/524">取得Smart Card的APDU Command</a>，說明如何側錄讀卡機的指令與回傳值</p>
<p>這篇文章將實作程式來讀取自然人憑證的卡號</p>
<p>程式參考於<a href="http://blog.blueshop.com.tw/timothychi/archive/2008/03/26/54591.aspx">使用C#讀取自然人評證卡號</a></p>
<p>但實作後仍無法正確顯示，所以使用 WinSCard APDU View Utility 來側錄指令後，修改成下面的程式碼</p>
<pre class="brush: vb; title: ;">
Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class DigitalCard

    Private Structure SCARD_IO_REQUEST
        Public dwProtocol As Integer
        Public cbPciLength As Integer
    End Structure

    '引用 PC/SC(Personal Computer/Smart Card) API WinScard.dll

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardEstablishContext(ByVal dwScope As UInteger, ByVal nNotUsed1 As Integer, ByVal nNotUsed2 As Integer, ByRef phContext As Integer) As Integer
    End Function

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardReleaseContext(ByVal phContext As Integer) As Integer
    End Function

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardConnect(ByVal hContext As Integer, ByVal cReaderName As String, ByVal dwShareMode As UInteger, ByVal dwPrefProtocol As UInteger, ByRef phCard As Integer, ByRef ActiveProtocol As Integer) As Integer
    End Function

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardDisconnect(ByVal hCard As Integer, ByVal Disposition As Integer) As Integer
    End Function

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardListReaders(ByVal hContext As Integer, ByVal cGroups As String, ByRef cReaderLists As String, ByRef nReaderCount As Integer) As Integer
    End Function

    &lt;DllImport(&quot;WinScard.dll&quot;)&gt; _
    Private Shared Function SCardTransmit(ByVal hCard As Integer, ByRef pioSendPci As SCARD_IO_REQUEST, ByVal pbSendBuffer() As Byte, ByVal cbSendLength As Integer, ByRef pioRecvPci As SCARD_IO_REQUEST, ByRef pbRecvBuffer As Byte, ByRef pcbRecvLength As Integer) As Integer
    End Function

    ''' &lt;summary&gt;
    ''' 取得自然人憑證的卡號
    ''' &lt;/summary&gt;
    ''' &lt;returns&gt;&lt;/returns&gt;
    ''' &lt;remarks&gt;&lt;/remarks&gt;
    Public Function GetCardNumber() As String
        Dim ContextHandle As Integer = 0, CardHandle As Integer = 0, ActiveProtocol As Integer = 0, ReaderCount As Integer = -1
        Dim ReaderList As String = String.Empty '讀卡機名稱列表
        Dim SendPci, RecvPci As SCARD_IO_REQUEST

        Dim SelEFAPDU_1() As Byte = {&amp;H80, &amp;HA4, &amp;H0, &amp;H0, &amp;H2, &amp;H3F, &amp;H0} 'Select Elementary File 的 APDU
        Dim SelEFAPDU_2() As Byte = {&amp;H80, &amp;HA4, &amp;H0, &amp;H0, &amp;H2, &amp;H9, &amp;H0} 'Select Elementary File 的 APDU
        Dim SelEFAPDU_3() As Byte = {&amp;H80, &amp;HA4, &amp;H0, &amp;H0, &amp;H2, &amp;H9, &amp;H3} 'Select Elementary File 的 APDU

        Dim ReadSNAPDU() As Byte = {&amp;H80, &amp;HB0, &amp;H0, &amp;H0, &amp;H10} '由offset 0 讀取 0x10位 Binary 資料的 APDU

        Dim SelEFRecvBytes(1) As Byte '應回 90 00
        Dim SelEFRecvLength As Integer = 2
        Dim SNRecvBytes(17) As Byte '接收卡號的 Byte Array
        Dim SnRecvLength As Integer = 18

        '建立 Smart Card API
        If SCardEstablishContext(0, 0, 0, ContextHandle) = 0 Then

            '列出可用的 Smart Card 讀卡機
            If SCardListReaders(ContextHandle, Nothing, ReaderList, ReaderCount) = 0 Then

                '建立 Smart Card 連線
                If SCardConnect(ContextHandle, ReaderList, 1, 2, CardHandle, ActiveProtocol) = 0 Then

                    RecvPci.dwProtocol = ActiveProtocol
                    SendPci.dwProtocol = RecvPci.dwProtocol

                    RecvPci.cbPciLength = 8
                    SendPci.cbPciLength = RecvPci.cbPciLength

                    '下達 Select FE14 檔的 APDU
                    If SCardTransmit(CardHandle, SendPci, SelEFAPDU_1, SelEFAPDU_1.Length, RecvPci, SelEFRecvBytes(0), SelEFRecvLength) = 0 Then
                        If SCardTransmit(CardHandle, SendPci, SelEFAPDU_2, SelEFAPDU_2.Length, RecvPci, SelEFRecvBytes(0), SelEFRecvLength) = 0 Then
                            If SCardTransmit(CardHandle, SendPci, SelEFAPDU_3, SelEFAPDU_3.Length, RecvPci, SelEFRecvBytes(0), SelEFRecvLength) = 0 Then

                                '下達讀取卡號指令
                                If SCardTransmit(CardHandle, SendPci, ReadSNAPDU, ReadSNAPDU.Length, RecvPci, SNRecvBytes(0), SnRecvLength) = 0 Then
                                    Return Encoding.Default.GetString(SNRecvBytes, 0, 16)
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
        Return &quot;&quot;
    End Function

End Class
</pre>
<p>使用的話請參考下面程式</p>
<pre class="brush: vb; title: ;">
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DGCard As New DigitalCard
        MsgBox(DGCard.GetCardNumber)
    End Sub
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/534/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GridView中滑鼠移動時，欄位會變色</title>
		<link>http://www.minitw.com/archives/513</link>
		<comments>http://www.minitw.com/archives/513#comments</comments>
		<pubDate>Mon, 23 Nov 2009 02:21:07 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=513</guid>
		<description><![CDATA[在GridView中如果想要在滑鼠移動時，滑鼠所指到的那一列會變色的話可以用JavaScript來達成

效果就像下面的圖所示，滑鼠所指到的那一列會變成亮黃色，移開後再還原成原本的顏色]]></description>
			<content:encoded><![CDATA[<p>在GridView中如果想要在滑鼠移動時，滑鼠所指到的那一列會變色的話可以用JavaScript來達成</p>
<p>效果就像下面的圖所示，滑鼠所指到的那一列會變成亮黃色，移開後再還原成原本的顏色</p>
<p><a href="http://www.flickr.com/photos/jokkson/4126870162/" title="Flickr 上 猴子銘 的 20091123_1"><img src="http://farm3.static.flickr.com/2661/4126870162_e7ba560edb.jpg" width="248" height="194" alt="20091123_1" /></a><br />
</ BR><br />
<a href="http://www.flickr.com/photos/jokkson/4126101103/" title="Flickr 上 猴子銘 的 20091123_2"><img src="http://farm3.static.flickr.com/2783/4126101103_1330dd14e7.jpg" width="249" height="197" alt="20091123_2" /></a></p>
<p>以下為程式碼片段，於RowDataBound的事件中綁定JavaScript到Row中</p>
<pre class="brush: vb; title: ;">
    Private Sub GridView1_RowDataBound(ByVal sender As Object, _
              ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
              Handles GridView1.RowDataBound
        '滑鼠移入移出效果。
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add(&quot;onmouseout&quot;, &quot;this.style.backgroundColor=currentcolor;&quot;)
            e.Row.Attributes.Add(&quot;onmouseover&quot;, &quot;currentcolor=this.style.backgroundColor; this.style.backgroundColor='#ffff40';&quot;)
        End If
    End Sub
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/513/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net 擴充方法(Extension Method)</title>
		<link>http://www.minitw.com/archives/502</link>
		<comments>http://www.minitw.com/archives/502#comments</comments>
		<pubDate>Fri, 13 Nov 2009 03:24:49 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Extension Method]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=502</guid>
		<description><![CDATA[什麼是擴充方法(Extension Method)呢?

簡單的說就是可以讓你自已擴充用的東西

在寫程式的時候，在字串的後面點(.)下去，會跑出一堆方法讓你使用，最常見的就是ToString()]]></description>
			<content:encoded><![CDATA[<p>什麼是擴充方法(Extension Method)呢?</p>
<p>簡單的說就是可以讓你自已擴充用的東西(有說跟沒說一樣.....)</p>
<p>不用把擴充方法想的太難，它其實也是很平易近人的</p>
<p>在寫程式的時候，在字串的後面點(.)下去，會跑出一堆方法讓你使用，最常見的就是ToString()</p>
<p>那麼我們要如何自行設計一個屬於自己的方法呢(結果如下圖)?其實不難</p>
<p><a title="Flickr 上 猴子銘 的 20091113_1" href="http://www.flickr.com/photos/jokkson/4099071843/"><img src="http://farm3.static.flickr.com/2447/4099071843_39c024c44a.jpg" alt="20091113_1" width="500" height="230" /></a></p>
<p>下程的範例程式(專案打包<a href="http://www.minitw.com/download/ExtensonMethodVB.rar">點我下載</a>)，研究一下應該就可以懂了</p>
<p>首先撰寫要自訂擴充的方法 ModuleExt.vb</p>
<p>這邊需要注意的地方，在於傳入的參數型態</p>
<p>如果傳入的參數型態是Integer，那麼只有型態是Integer的點下去才會出這個自訂的Method</p>
<p>如果想要任何型態點下去，都會帶出現我們自定的Method，</p>
<p>那麼就把型態定為Object就可以了(如本例的AddString)</p>
<pre class="brush: vb; title: ;">
Imports System.Runtime.CompilerServices

Namespace ExtensionMethods
    Module OtherExtensions

        ''' &lt;summary&gt;
        ''' 英文字首轉大寫
        ''' &lt;/summary&gt;
        &lt;Extension()&gt; _
        Public Function ToUpperFirstWord(ByVal src As String) As String
            If src.Length &gt;= 1 Then
                Dim FirstWord As String = src.Substring(0, 1).ToUpper
                src = src.Remove(0, 1).Insert(0, FirstWord)
            End If
            Return src
        End Function

        &lt;Extension()&gt; _
        Public Function ToPerCent(ByVal src As Double) As String
            Return src * 100 &amp; &quot;%&quot;
        End Function

        &lt;Extension()&gt; _
        Public Function AddString(ByVal src As Object) As String
            Return src &amp; &quot; New AddString&quot;
        End Function

    End Module
End Namespace
</pre>
<p>接下來則是在要使用的程式頁面引用之前所寫的Extension</p>
<pre class="brush: vb; title: ;">
Imports ConsoleApplicationTEST.ExtensionMethods.OtherExtensions

Module Module1

    Sub Main()
        Dim test As String = &quot;abcd&quot;
        'Output: Abcd
        Console.WriteLine(test.ToUpperFirstWord)
        'Output: abcd New AddString
        Console.WriteLine(test.AddString)
        'Output: Abcd New AddString
        Console.WriteLine(test.ToUpperFirstWord.AddString)

        'Output: 50%
        Dim testint As Double = 0.5
        Console.WriteLine(testint.ToPerCent)

        Console.ReadLine()
    End Sub

End Module
</pre>
<p>相關文章：<br />
<a href="http://sophiecheng.spaces.live.com/Blog/cns!A88551252299771F!519.entry">何謂擴充方法 (Extension method )？</a><br />
<a href="http://blog.miniasp.com/post/2008/01/Share-my-first-Extension-Method.aspx">C# 3.0 初體驗：Extension Method </a><br />
<a href="http://godleon.blogspot.com/2009/06/c-30-extension-method.html">[C#] 3.0 中的新功能 - 擴充方法(Extension Method)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/502/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>好用的屬性設定工具  PropertyGrid</title>
		<link>http://www.minitw.com/archives/473</link>
		<comments>http://www.minitw.com/archives/473#comments</comments>
		<pubDate>Wed, 16 Sep 2009 02:37:49 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[PropertyGrid]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=473</guid>
		<description><![CDATA[PropertyGrid 這個元件在市面上 .net  的書很少看到

這幾天摸了一下，感覺上是個還不錯用的元件

尤其對於在開發"編輯環境"的特別好用

簡單的說，這是一個可以幫你把Class變成設定介面的元件

然後元件就會幫你處理傳值與顯示值的問題]]></description>
			<content:encoded><![CDATA[<p>PropertyGrid 這個元件在市面上 .net  的書很少看到</p>
<p>這幾天摸了一下，感覺上是個還不錯用的元件</p>
<p>尤其對於在開發"編輯環境"的特別好用</p>
<p>簡單的說，這是一個可以幫你把Class變成設定介面的元件</p>
<p>把Class丟進元件後，元件就會幫你處理傳值與顯示值的問題</p>
<p>看圖或許比較好理解</p>
<p><a href="http://lh3.ggpht.com/_HUcF0uqL0MM/SrBIn8N7V2I/AAAAAAAAAv4/OjUd3wrm_6Y/s800/20090916_1.jpg"><img class="alignnone" src="http://lh3.ggpht.com/_HUcF0uqL0MM/SrBIn8N7V2I/AAAAAAAAAv4/OjUd3wrm_6Y/s800/20090916_1.jpg" alt="" width="281" height="333" /></a></p>
<p>有沒有一種很熟悉的感覺，沒錯，跟 Visual Studio .Net 的的屬性設定是一樣的</p>
<p>而這個介面只要把寫好的Class放進去就可以自動產生了，真的超方便</p>
<p>完整的程式碼可以到<a href="http://sites.google.com/site/minitwfile/Home/file/PropertyGrid_Sample.rar">這邊下載</a></p>
<pre class="brush: vb; title: ;">
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        '把Class丟進去PropertyGrid
        PropertyGrid1.SelectedObject = New SampleClass
    End Sub
</pre>
<p>SampleClass.vb</p>
<pre class="brush: vb; title: ;">
Imports System.ComponentModel

Public Class SampleClass

    &lt;FlagsAttribute()&gt; _
   Public Enum Permissions
        &lt;Description(&quot;未設定&quot;)&gt; _
        None = 0

        &lt;Description(&quot;建立&quot;)&gt; _
        Create = 1

        &lt;Description(&quot;讀取&quot;)&gt; _
        Read = 2

        &lt;Description(&quot;更新&quot;)&gt; _
        Update = 4

        &lt;Description(&quot;刪除&quot;)&gt; _
        Delete = 8

        &lt;Description(&quot;所有功能&quot;)&gt; _
        All = Create Or Read Or Update Or Delete

    End Enum

    Private _P1 As String
    Public Property P1_String() As String
        Get
            Return _P1
        End Get
        Set(ByVal value As String)
            _P1 = value
        End Set
    End Property

    Private _P2 As Integer
    Public Property P2_Integer() As Integer
        Get
            Return _P2
        End Get
        Set(ByVal value As Integer)
            _P2 = value
        End Set
    End Property

    Private _P3 As Boolean
    Public Property P3_Boolen() As Boolean
        Get
            Return _P3
        End Get
        Set(ByVal value As Boolean)
            _P3 = value
        End Set
    End Property

    Private _P4 As DateTime
    Public Property P4_DateTime() As DateTime
        Get
            Return _P4
        End Get
        Set(ByVal value As DateTime)
            _P4 = value
        End Set
    End Property

    Private _P5 As Permissions
    Public Property P5_Enum() As Permissions
        Get
            Return _P5
        End Get
        Set(ByVal value As Permissions)
            _P5 = value
        End Set
    End Property

    Private _P6 As New PropertyTreeClass.AddressType
    &lt;DesignerSerializationVisibility(DesignerSerializationVisibility.Content)&gt; _
    &lt;Description(&quot;住址&quot;)&gt; _
    Public Property P6_Tree() As PropertyTreeClass.AddressType
        Get
            Return _P6
        End Get
        Set(ByVal value As PropertyTreeClass.AddressType)
            _P6 = value
        End Set
    End Property

    Private _P7 As Color = Color.White
    Public Property P7_Color() As Color
        Get
            Return _P7
        End Get
        Set(ByVal value As Color)
            _P7 = value
        End Set
    End Property

    Private _P8 As Color = System.Drawing.Color.FromArgb(123, 123, 123)
    &lt;Description(&quot;於自訂項目的下面空格中按下滑鼠右鍵，可自訂RGB&quot;)&gt; _
    Public Property P8_Color() As Color
        Get
            Return _P8
        End Get
        Set(ByVal value As Color)
            _P8 = value
        End Set
    End Property

#Region &quot;可分類的屬性&quot;
    Private _C1 As String
    &lt;Category(&quot;分類&quot;)&gt; _
    &lt;Description(&quot;相同類型的屬性C1&quot;)&gt; _
    Public Property C1() As String
        Get
            Return _C1
        End Get
        Set(ByVal value As String)
            _C1 = value
        End Set
    End Property

    Private _C2 As String
    &lt;Category(&quot;分類&quot;)&gt; _
    &lt;Description(&quot;相同類型的屬性C2&quot;)&gt; _
    Public Property C2() As String
        Get
            Return _C2
        End Get
        Set(ByVal value As String)
            _C2 = value
        End Set
    End Property
#End Region

End Class
</pre>
<p>PropertyTreeClass.vb</p>
<pre class="brush: vb; title: ;">
Imports System.ComponentModel
Imports System.Globalization

'The namespace referenced from
'http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f81b6caa-5fae-45c4-ad46-2240e84a5d7a

Namespace PropertyTreeClass

    &lt;TypeConverter(GetType(AddressTypeTypeConverter))&gt; _
    Public Class AddressType

        Private m_country As String
        &lt;NotifyParentProperty(True), Description(&quot;國家&quot;), RefreshProperties(RefreshProperties.Repaint)&gt; _
        Public Property Country() As String
            Get
                Return m_country
            End Get

            Set(ByVal value As String)
                m_country = value
            End Set
        End Property

        Private m_city As String
        &lt;NotifyParentProperty(True), Description(&quot;城市&quot;), RefreshProperties(RefreshProperties.Repaint)&gt; _
        Public Property City() As String
            Get
                Return m_city
            End Get

            Set(ByVal value As String)
                m_city = value
            End Set
        End Property
    End Class

    Public Class Person

        Public Sub New()
            homeAddressField = New AddressType()
        End Sub

        Private homeAddressField As AddressType

        &lt;DesignerSerializationVisibility(DesignerSerializationVisibility.Content)&gt; _
        Public Property HomeAddress() As AddressType
            Get
                Return Me.homeAddressField
            End Get

            Set(ByVal value As AddressType)
                Me.homeAddressField = value
            End Set
        End Property
    End Class

    Public Class AddressTypeTypeConverter
        Inherits TypeConverter

        Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
            'This method is used to shown information in the PropertyGrid.
            If destinationType Is GetType(String) Then
                Return (DirectCast(value, AddressType).Country &amp; &quot;,&quot;) + DirectCast(value, AddressType).City
            End If

            Return MyBase.ConvertTo(context, culture, value, destinationType)
        End Function

        Public Overrides Function GetProperties(ByVal context As ITypeDescriptorContext, ByVal value As Object, ByVal attributes As Attribute()) As PropertyDescriptorCollection
            Return TypeDescriptor.GetProperties(GetType(AddressType), attributes).Sort(New String() {&quot;Country&quot;, &quot;City&quot;})
        End Function

        Public Overrides Function GetPropertiesSupported(ByVal context As ITypeDescriptorContext) As Boolean
            Return True
        End Function

    End Class

End Namespace
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/473/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>取得Enum程式碼中的描述</title>
		<link>http://www.minitw.com/archives/469</link>
		<comments>http://www.minitw.com/archives/469#comments</comments>
		<pubDate>Tue, 15 Sep 2009 01:13:19 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[Attribute]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=469</guid>
		<description><![CDATA[先import 下面這2個namespace
Imports System.ComponentModel
Imports System.Reflection]]></description>
			<content:encoded><![CDATA[<p>先import 下面這2個namespace<br />
Imports System.ComponentModel<br />
Imports System.Reflection</p>
<pre class="brush: vb; title: ;">

&lt;FlagsAttribute()&gt; _
Public Enum Permissions

&lt;Description(&quot;未設定&quot;)&gt; _
None = 0

&lt;Description(&quot;建立&quot;)&gt; _
Create = 1

&lt;Description(&quot;讀取&quot;)&gt; _
Read = 2

&lt;Description(&quot;更新&quot;)&gt; _
Update = 4

&lt;Description(&quot;刪除&quot;)&gt; _
Delete = 8

&lt;Description(&quot;所有功能&quot;)&gt; _
All = Create Or Read Or Update Or Delete

End Enum

'要取得描述時使用下面的程式碼

Dim fi As FieldInfo = _
Permissions.Create.GetType().GetField(Permissions.Create.ToString())

Dim attributes As DescriptionAttribute() = _
CType(fi.GetCustomAttributes(GetType(DescriptionAttribute), False),  _
DescriptionAttribute())

'顯示取得的描述
Response.Write(attributes(0).Description)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/469/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解決SQL Server 2005建View時不能正常排序(Order by)的問題</title>
		<link>http://www.minitw.com/archives/441</link>
		<comments>http://www.minitw.com/archives/441#comments</comments>
		<pubDate>Mon, 20 Jul 2009 03:44:03 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[Order by]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[View]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=441</guid>
		<description><![CDATA[當View建好了，也存檔了之後，再把View開起來

你會發現其實這個View並沒有依照我們的意思Order by

而解決問題的方法就是不要使用PERCENT，改用一個數值很大的值....]]></description>
			<content:encoded><![CDATA[<p>在SQL Server 2005中建View時如果你是用介面幫你產生的</p>
<p>應該會是像下面的指令碼一樣</p>
<pre class="brush: sql; title: ;">

SELECT     TOP (100) PERCENT MsgText
FROM         dbo.RouterOS_All
ORDER BY MsgDateTime DESC
</pre>
<p>當View建好了，也存檔了之後，再把View開起來</p>
<p>你會發現其實這個View並沒有依照我們的意思Order by</p>
<p>而解決問題的方法就是不要使用PERCENT，改用一個數值很大的值</p>
<pre class="brush: sql; title: ;">

SELECT     TOP (2147483647) MsgText
FROM         dbo.RouterOS_All
ORDER BY MsgDateTime DESC
</pre>
<p>這樣子就正常了。至於這是不是個Bug，我想就只能問MS了</p>
<p>測試環境：<br />
SQL Server 2005 Express with SP3<br />
Windows 2008 Std with SP1 x86</p>
<p>參考資料：<a href="http://oakleafblog.blogspot.com/2006/09/sql-server-2005-ordered-view-and.html" target="_blank"><br />
SQL Server 2005 Ordered View and Inline Function Problems</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/441/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用LINQ來取得特定副檔名的檔案</title>
		<link>http://www.minitw.com/archives/430</link>
		<comments>http://www.minitw.com/archives/430#comments</comments>
		<pubDate>Thu, 16 Jul 2009 02:59:25 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[副檔名]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=430</guid>
		<description><![CDATA[有了LINQ後，要濾出我們想要副檔名的檔案，真的蠻簡單的 花了一些時間寫了一個副程式，有需要的朋友可以拿去使用 如果你需要遞迴尋找的話(即該目錄下的所有子目錄也要找)，把第3參數帶True進去即可 程式使用方式請看下面 '使用方式(只找1層) Dim files As List(Of FileInfo) = _ GetPathFile(txt_batch_patch.Text, New String() {&#34;.png&#34;, &#34;.jpg&#34;}) lst_filename.Items.Clear() For Each s As FileInfo In files lst_filename.Items.Add(s.Name) Next '使用方式(遞迴尋找) Dim files As List(Of FileInfo) = _ GetPathFile(txt_batch_patch.Text, New String() {&#34;.png&#34;, &#34;.jpg&#34;}, True) lst_filename.Items.Clear() For Each s As FileInfo In files lst_filename.Items.Add(s.Name) Next . . 完整的副程式如下 ''' [...]]]></description>
			<content:encoded><![CDATA[<p>有了LINQ後，要濾出我們想要副檔名的檔案，真的蠻簡單的</p>
<p>花了一些時間寫了一個副程式，有需要的朋友可以拿去使用</p>
<p>如果你需要遞迴尋找的話(即該目錄下的所有子目錄也要找)，把第3參數帶True進去即可</p>
<p>程式使用方式請看下面</p>
<pre class="brush: vb; title: ;">
'使用方式(只找1層)
Dim files As List(Of FileInfo) = _
GetPathFile(txt_batch_patch.Text, New String() {&quot;.png&quot;, &quot;.jpg&quot;})

lst_filename.Items.Clear()

For Each s As FileInfo In files
    lst_filename.Items.Add(s.Name)
Next

'使用方式(遞迴尋找)
Dim files As List(Of FileInfo) = _
GetPathFile(txt_batch_patch.Text, New String() {&quot;.png&quot;, &quot;.jpg&quot;}, True)

lst_filename.Items.Clear()

For Each s As FileInfo In files
    lst_filename.Items.Add(s.Name)
Next
</pre>
<p><span style="color: #ffffff;">.</span><br />
<span style="color: #ffffff;">.</span></p>
<p>完整的副程式如下</p>
<pre class="brush: vb; title: ;">
    ''' &lt;summary&gt;
    ''' 取得目錄下副檔名為特定格式的檔案
    ''' &lt;/summary&gt;
    ''' &lt;param name=&quot;DirPath&quot;&gt;起始目錄&lt;/param&gt;
    ''' &lt;param name=&quot;file_extension&quot;&gt;要尋找的副檔名&lt;/param&gt;
    ''' &lt;param name=&quot;IsRecursive&quot;&gt;是否要尋找子目錄(預設值為不尋找子目錄)&lt;/param&gt;
    ''' &lt;returns&gt;List(Of FileInfo)&lt;/returns&gt;
    ''' &lt;remarks&gt;&lt;/remarks&gt;
    Private Function GetPathFile(ByVal DirPath As String, _
                                 ByVal file_extension As String(), _
                                 Optional ByVal IsRecursive As Boolean = False) _
                                 As List(Of FileInfo)

        '取得目錄下所有的資料夾
        Dim DirectoryPath As New List(Of String)
        DirectoryPath = My.Computer.FileSystem.GetDirectories(DirPath).ToList
        Dim Files As New List(Of FileInfo)

        If IsRecursive = True Then
            For Each DirName As String In DirectoryPath
                If System.IO.Directory.Exists(DirName) Then
                    '讓程式不要停止回應
                    Application.DoEvents()
                    '如果存在下一層的資料夾就遞迴呼叫
                    Files.AddRange(GetPathFile(DirName, file_extension, IsRecursive))
                End If
            Next
        End If

        DirectoryPath.Add(DirPath)
        For Each DirStr As String In DirectoryPath

            '取得目錄下所有的檔案名稱(String)
            Dim myFiles = From s In My.Computer.FileSystem.GetFiles(DirStr)

            '先把檔案名稱轉成FileInfo
            Dim f As New List(Of FileInfo)
            For Each s As String In myFiles
                f.Add(My.Computer.FileSystem.GetFileInfo(s))
            Next

            '使用LINQ來取出我們要的資料(副檔名包含在ImageExtension()裡面的)
            Dim files_filter As IEnumerable(Of FileInfo) = _
            From s In f _
            Where file_extension.Contains(s.Extension.ToLower)

            Files.AddRange(files_filter.ToList)

        Next

        Return Files

    End Function
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/430/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在 AJAX 取得 PopupControlExtender 回傳的值 with UserControl</title>
		<link>http://www.minitw.com/archives/381</link>
		<comments>http://www.minitw.com/archives/381#comments</comments>
		<pubDate>Fri, 08 May 2009 01:44:55 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[PopupControlExtender]]></category>
		<category><![CDATA[UserControl]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=381</guid>
		<description><![CDATA[在一般的 PopupControlExtender  中要取得目前頁面元件回傳的值並不困難

詳細可以參考這篇文章]]></description>
			<content:encoded><![CDATA[<p>在一般的 PopupControlExtender  中要取得目前頁面元件回傳的值並不困難</p>
<p>詳細可以參考這篇文章<br />
<a id="viewpost_ascx_TitleUrl" title="Title of this entry." href="http://www.dotblogs.com.tw/lolota/archive/2009/03/18/7554.aspx">[KB]如果UpdatePanel有多個觸發來源，要怎麼將內容Post回去原觸發的控制項呢？</a></p>
<p>這邊列出重點程式碼</p>
<pre class="brush: vb; title: ;">

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) _
                                                        Handles DropDownList1.SelectedIndexChanged
        Dim tmppce As AjaxControlToolkit.PopupControlExtender
        tmppce = AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page)
        tmppce.Commit(DropDownList1.SelectedValue.ToString())
    End Sub
</pre>
<p>可以發現回傳的值是寫在元件的事件觸發之中</p>
<p>可是如果我們是使用 UserControl 那該如何解決呢</p>
<p>很簡單，只要在 UserControl 中新增一個事件，並且於 UserControl 觸發該事件就可以了</p>
<p>感覺很像很複雜，其實不會，看程式或許會比較好了解一點</p>
<p>先建立一個 UserControl ，並且加入一個 TreeView 元件</p>
<pre class="brush: xml; title: ;">
&lt;asp:TreeView ID=&quot;TreeView1&quot; runat=&quot;server&quot; BackColor=&quot;#66FFFF&quot;&gt;
    &lt;Nodes&gt;
        &lt;asp:TreeNode Text=&quot;測試1&quot; Value=&quot;111111&quot;&gt;
            &lt;asp:TreeNode Text=&quot;測試1_1&quot; Value=&quot;新節點&quot;&gt;&lt;/asp:TreeNode&gt;
        &lt;/asp:TreeNode&gt;
        &lt;asp:TreeNode Text=&quot;測試2&quot; Value=&quot;222222222&quot;&gt;&lt;/asp:TreeNode&gt;
        &lt;asp:TreeNode Text=&quot;測試3&quot; Value=&quot;33333&quot;&gt;&lt;/asp:TreeNode&gt;
    &lt;/Nodes&gt;
&lt;/asp:TreeView&gt;
</pre>
<p>然後在 UserControl 中新增一個事件，且設定 TreeView 的 SelectedNodeChanged 會觸發該新增的事件</p>
<pre class="brush: vb; title: ;">
    Public Event UC_Event(ByVal srt As String)

    Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As EventArgs) _
                                            Handles TreeView1.SelectedNodeChanged
        RaiseEvent UC_Event(TreeView1.SelectedNode.Text)
    End Sub
</pre>
<p>接下來於主頁面中把該 UserControl 拉進來，然後新增程式於 UC_Event 事件中</p>
<pre class="brush: vb; title: ;">
  Private Sub UC1_UC_Event(ByVal srt As String) Handles UC1.UC_Event
        Dim tmppce As AjaxControlToolkit.PopupControlExtender
        tmppce = AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page)
        tmppce.Commit(srt)
    End Sub
</pre>
<p>這樣子我們就有一個可以在 PopupControlExtender 放入 UserControl ，而且也可以有回傳值了</p>
<p><a href="http://lh5.ggpht.com/_HUcF0uqL0MM/SgOL5_i6mcI/AAAAAAAAAdk/pTKyLQJnLB0/s800/20090508_1.JPG"><img alt="" src="http://lh5.ggpht.com/_HUcF0uqL0MM/SgOL5_i6mcI/AAAAAAAAAdk/pTKyLQJnLB0/s800/20090508_1.JPG" class="alignnone" width="184" height="187" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/381/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>在 .net 上實現 PHP 的 Crypt 函式</title>
		<link>http://www.minitw.com/archives/378</link>
		<comments>http://www.minitw.com/archives/378#comments</comments>
		<pubDate>Wed, 29 Apr 2009 06:24:51 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Crypt]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.minitw.com/?p=378</guid>
		<description><![CDATA[在 PHP 上有個 Crypt 函式是用來加密字串的

很多都用的到，例如：LDAP 上的密碼加密

那麼要如何在 .net 上實現這個函式呢

其實已經有人寫好，等我們去用了

A C# implementation of Unix crypt()

把原始檔案下載下來後是個 C# 的程式檔

先在 Visual Studio 中開一個新類別庫專案(C#)，把檔案加入

然後就可以建成 dll 檔來使用了]]></description>
			<content:encoded><![CDATA[<p>在 PHP 上有個 Crypt 函式是用來加密字串的</p>
<p>很多都用的到，例如：LDAP 上的密碼加密</p>
<p>那麼要如何在 .net 上實現這個函式呢</p>
<p>其實已經有人寫好，等我們去用了</p>
<p><a href="http://www.codeproject.com/KB/cs/unixcrypt.aspx">A C# implementation of Unix crypt()</a></p>
<p>把原始檔案下載下來後是個 C# 的程式檔</p>
<p>先在 Visual Studio 中開一個新類別庫專案(C#)，把檔案加入</p>
<p>然後就可以建成 dll 檔來使用了</p>
<p>本來有想說改成 VB.Net 的版本，不過轉換過後有些地方怪怪的就放棄了</p>
<p>這邊有<a href="http://sites.google.com/site/minitwfile/Home/file/Unixcrypt.rar?attredirects=0">打包好的版本</a>，有興趣的可以下載回去研究</p>
<p><a href="http://lh6.ggpht.com/_HUcF0uqL0MM/SffwMwz77oI/AAAAAAAAAcs/OlI-mPZ-bYY/s800/20090429_1.jpg"><img class="alignnone" src="http://lh6.ggpht.com/_HUcF0uqL0MM/SffwMwz77oI/AAAAAAAAAcs/OlI-mPZ-bYY/s800/20090429_1.jpg" alt="" width="255" height="253" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minitw.com/archives/378/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

