四月 14
DocProject 是一個在.NET下,可以幫你自動產生程式碼文件的東西
詳細的介紹可到作者網站參考
中文的資料可參考使用DocProject外速產生.NET物件文件(一) - 黃偉榮的學習筆記- 博客園
如果你安裝完成後,使用Visual Studio 2008建立DocProject專案後
此時可以在Visual Studio內進行建置,並不會有錯誤
但如果是用DocProject External UI來開啟專案你就會收到一個錯誤,像下圖
這是因為程式找不到輸出的路徑

解決方法如下:
1.先使用記事本開啟DocProject的專案檔(csproj 或 vbproj)
2.於第一個<PropertyGroup>內插入<OutputPath>bin\</OutputPath>。如下圖所示

接下來就可以順利使用DocProject External UI了
建置時,別忘了選擇編譯的CPU類型

三月 15
XDocument是Linq所提供的一個關於XML的類別
但有的時候我們所使用的方法要求傳入的是XmlDocument
但是在傳入之前,我們想要針對這個XML檔案做一些處理後,再傳進去
這時候就可以利用XDocument,經由Linq處理後,再轉成XmlDocument丟進去
註:用了Linq to XML,終於可以離開之前寫XML相關處理的惡夢,Linq真是個好東西
話不多說了,直接來看程式吧
using System.Xml.Linq;
XDocument XDoc = XDocument.Load(Log4NetConfigXMLFilePath);
var nodes = (from p in XDoc.Elements("log4net")
.Elements("appender")
.Elements("file")
elect p).FirstOrDefault();
//使用Linq Select出來後,進行處理
nodes.SetAttributeValue("value",HttpContext.Current.Server.MapPath("~/") +
nodes.Attribute("value").Value);
//轉出來後再放到XmlDocument
System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
//把XDocument轉成XmlDocument
XmlDoc.LoadXml(XDoc.Document.ToString());
三月 09
一般在ASP.NET中要載入圖片,都是要先把圖片存成檔案
然後把Image的Url指向圖片檔案
但是如果圖片的來源是資料庫的二進位值,或是由系統產生無實體圖片就無法這麼做了
解決方法就是使用泛型處理常式(ashx)
首先新增一個泛型處理常式(ashx)

然後把程式寫在裡面(程式碼請往下看)
最後把Image的Url位置指向我們新增的ashx檔的位置即可

範例程式:測試程式的專案檔
Default.aspx
'把實體圖片讀成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("20100309_1.jpg"))
Dim b(f.Length) As Byte
f.Read(b, 0, f.Length - 1)
Session("pic") = b
End Sub
Showlogo.ashx
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("pic")
context.Response.ContentType = "text/jpg"
context.Response.BinaryWrite(b)
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
參考資料:
在 HttpHandler 中使用 Session 的注意事項
利用 ASP.NET的泛型處理常式(Handler)產生圖片驗證碼,結合IRequiresSessionState將驗證碼儲存在session裡,透過 session值來驗證
三月 08
對於我這個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;
二月 21
快被載入順序煩死了,幸好有好心人提供,以下為文章
資料來源網站:瓶水相逢.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 主版和內容頁面中的事件