星期二, 6月 23, 2009

特殊符號編碼

今天系統突然沒反應
看了才發現原來xml裡有特殊符號 造成xml判斷錯誤







< 小於&lt;
> 大於&gt;
& 和&amp;
' 單引號&apos;
" 雙引號 &quot;
斷行符號 &#13


特殊字符編碼大全 ... 自已google

透過C#寄發mail

1.直接寄發
透過System.Net.Mail,舊的System.Web.Mail不用了
reference
MailMessage 類別


2.呼叫outlook
需加入參考「 Microsoft Outlook 11.0 Object Library」
Outlook.ApplicationClass app = new Outlook.ApplicationClass();
Outlook.MailItemClass mi = (Outlook.MailItemClass)app.CreateItem(Outlook.OlItemType.olMailItem);
mi.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mi.To = "yurenju@gmail.com";
mi.Display(new object());


references
C# 呼叫 Outlook

3.呼叫預設email程式
private void StartDefaultClient()
{
string filename = "mailto:jismenon@yahoo.com?subject=Hello&body=Hello&cc=meera@yahoo.com&bcc=jany@yahoo.com&Attach=@C:\\test.txt";
Process myProcess = new Process();
myProcess.StartInfo.FileName = filename;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
}

references
Opening default Email client from a C# Application


p.s 斷行問題
body裡有斷行時,要改用escape("\n") 或 %0A
否則會沒效果

星期三, 6月 03, 2009

將DataTable裡的Byte column存入access

string[] myPicArrayTitle = new string[] { "Pic1", "Pic2"};
foreach(string title in myPicArrayTitle )
{
string strSQL = string.Format("Update PicInfo Set {0}=@{0} Where PicSN={1}", title, PicSN);
accessAdapter.MdbAccessOLE(strSQL , title,(byte[])dt.Rows[0][title]);
}
public bool MdbAccessOLE(string strSQL,string ColName ,byte[] FileByteArray)
{
this.my_StrConnection = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + this.my_TablePath;
OleDbConnection my_conn = new OleDbConnection(this.my_StrConnection);
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = my_conn;
cmd.CommandText = strSQL;
cmd.Parameters.Add("@"+ColName, System.Data.OleDb.OleDbType.Binary, FileByteArray.Length).Value = FileByteArray;

bool result = true;
try
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
result = false;
SharedAPI.Log_Error("MDB操作失敗, 錯誤訊息:" + ex.Message + " SQL:" + strSQL);
}
finally
{
cmd.Connection.Close();
}
return result;
}