2017年12月6日 星期三

Robocopy and a Few Examples

https://social.technet.microsoft.com/wiki/contents/articles/1073.robocopy-and-a-few-examples.aspx

利用robocopy複製資料夾結構(不複製檔案)

robocopy /zb /e /xf *

https://social.technet.microsoft.com/Forums/lync/en-US/0b3d3006-0e0f-4c95-9e2f-4c820832ebfa/using-robocopy-to-copy-folder-structure-only?forum=w7itprogeneral

/zb allows you access into the folders that you DON'T have permission to.  This will let you pull a complete folder structure even to the folders you haven't been granted permission to so that you don't have to mess with permissions to get this information.

2017年11月12日 星期日

WHERE 0 = (( CAST(CHARINDEX(N'Bill', [Extent1].[NAME]) AS int)) - 1)

            var result = from s1 in context.EMPLOYEE
                         where s1.NAME.IndexOf("Bill") == 0

=>上面的LINQ語法會產生以下SQL語法,滿少用到CHARINDEX
SELECT
    [Extent1].[ID] AS [ID],
    [Extent1].[NAME] AS [NAME]
    FROM [dbo].[EMPLOYEE] AS [Extent1]
    WHERE 0 = (( CAST(CHARINDEX(N'Bill', [Extent1].[NAME]) AS int)) - 1)

2017年11月6日 星期一

2017年11月1日 星期三

RAID 10、64 KB、SQL Server

Disk Performance Hands On, Part 2: RAID 10 Performance
http://www.kendalvandyke.com/2009/02/disk-performance-hands-on-part-2-raid.html
RAID 10 is the most commonly recommended type of configuration to house OLTP data files for SQL Server

SQL Server裝機磁區格式化需要使用64 KB的配置單位大小

https://www.sqlservercentral.com/Forums/Topic1804884-3411-1.aspx
SQL performs disk IO in extents and an extent is 8 pages, each of which are 8KB, for a total of 64KB

[SQL Server]改善I/O效能- NTFS Allocation Unit Size(4KB vs 64KB)
https://dotblogs.com.tw/stanley14/2016/09/18/063116

[SQL Server][裝機]:格式化資料磁碟,使用 64 KB 的 NTFS 配置單位大小(allocation unit size)
http://sharedderrick.blogspot.tw/2017/05/sql-server-64-kb-ntfs-allocation-unit.html

Understanding Pages and Extents
https://technet.microsoft.com/en-us/library/ms190969(v=sql.105).aspx

Disk Partition Alignment Best Practices for SQL Server
https://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx

Introduction to Page and Extent in Sql Server
http://sqlhints.com/tag/pages-from-uniform-extent-in-sql-server-2016/

2017年10月31日 星期二

CHARACTER_SET_NAME是cp950,char還是可以存Big5中文字

雖然可以存繁體中文
還是建議使用nchar(10)可以存十個中文字
char(10)因中文字占 2Byte只能存五個中文字,通常長度10後端程式就當你可以存十個中文字



SELECT CHARACTER_SET_NAME,COLLATION_NAME, * FROM [INFORMATION_SCHEMA].[COLUMNS]
WHERE [TABLE_SCHEMA] = 'dbo'
AND [TABLE_NAME] ='Table1'

Chinese_Taiwan_Stroke_CS_AS => cp950

Chinese_Taiwan_Stroke_BIN => cp950

Latin1_General_100_BIN => iso_1

Chinese_PRC_Stroke_CS_AS => cp936

Chinese_Hong_Kong_Stroke_90_BIN2 => cp950


SELECT * FROM sys.fn_helpcollations()  
WHERE name LIKE 'Chinese_%'

Windows 定序
https://docs.microsoft.com/zh-tw/sql/t-sql/statements/windows-collation-name-transact-sql
SELECT * FROM sys.fn_helpcollations() WHERE name NOT LIKE 'SQL%'; 

SQL Server 定序
https://docs.microsoft.com/zh-tw/sql/t-sql/statements/sql-server-collation-name-transact-sql
SQL Server 支援 Windows 定序。 SQL Server 也支援有限數目 (小於80) 的定序,稱為 SQL Server 定序,這些定序是在 SQL Server 支援 Windows 定序之前開發。 為了回溯相容性, SQL Server 定序仍然受到支援,但是不應該用於新的開發工作。


SELECT  t1,CONVERT(VARBINARY, t1) AS t1BINARY,t2,CONVERT(VARBINARY, t2) AS t2BINARY
FROM Table1
 

參考資料:BIG5難字寫入資料庫(Unicode篇)
https://dotblogs.com.tw/stanley14/2015/11/11/153893

CNS11643碼表查詢
http://www.cns11643.gov.tw/AIDB/codetable_search.do

2D4E (欄位t1是nchar)

A4E5 (欄位t2是char)

延伸閱讀:
https://openhome.cc/Gossip/Encoding/UnicodeUTF.html
Windows記事本選擇「Unicode」時,實際上採用的是UCS-2/UTF-16 Little Endian
https://stackoverflow.com/questions/1379416/insert-utf8-data-into-a-sql-server-2008


2017年10月29日 星期日

Package migration from version 8 to version 6 failed

https://ssis2014downgrade.codeplex.com

可以搜尋dtsx找關鍵字PackageFormatVersion
SQL Server 2012是6,SQL Server 2014和SQL Server 2016是8
可以用SSIS2014 Downgrade工具降版成SQL Server 2012的dtsx
封裝檔就可以匯入SQL Server 2012

秀出TSQL語法剖析、編譯、執行時間

DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
SET STATISTICS IO ON;
SET STATISTICS TIME ON;


http://www.cnblogs.com/hyqiang168/archive/2008/01/19/1045616.html
1.测试前用二条命令清除SQL Server的数据和过程缓冲区,以保证测试条件相同:
DBCC DROPCLEANBUFFERS和DBCC FREEPROCCACHE
2.SET STATISTICS TIME:看cpu时间   
3.SET STATISTICS IO:关注scan count(计数)------查询读取的表数量   logical read( 逻辑读)次数

2017年10月24日 星期二

忘記SQL Server的管理密碼

http://sharedderrick.blogspot.tw/2009/11/sa-windows-administrator-sql-serveri.html

以「單一使用者模式(single user mode)」來啟動 SQL Server 執行個體
命令提示字元
net start mssqlserver /m

2017年8月23日 星期三

Schema Zen - Script and create SQL Server objects quickly

https://github.com/sethreno/schemazen

D:\ExportSchema\SchemaZen.exe script --server 127.0.0.1 --database 資料庫名稱 --scriptDir D:\ExportSchema\

除了script參數以外,還有create和compare
script參數:generate sql scripts for all objects in the database
create參數:create a database named db from the sql scripts
compare參數:compare databases

sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty(SQL Server物件的擴充屬性)

--新增註解
EXEC sp_addextendedproperty @name=N'使用者代碼', @value=N'' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTable', @level2type=N'COLUMN',@level2name=N'ACCOUNTID'


--更新註解
EXEC sp_updateextendedproperty @name=N'使用者代碼', @value=N'長度25' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTable', @level2type=N'COLUMN',@level2name=N'ACCOUNTID'

--刪除註解
EXEC sp_dropextendedproperty @name=N'使用者代碼', @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTable', @level2type=N'COLUMN',@level2name=N'ACCOUNTID'


The Will Will Web | 如何編輯 SQL Server 中物件的擴充屬性(Extended Property)
https://blog.miniasp.com/post/2008/07/19/How-to-access-SQL-Server-Objects-Extended-Property.aspx

利用forfiles指令刪除7天前的檔案和資料夾

forfiles /P D:\ExportData\ /S /M *.* /D -7 /C "cmd /c del @PATH"
forfiles /p D:\ExportData\ /D -7 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"

2017年6月25日 星期日

TextTemplatingFilePreprocessor

https://msdn.microsoft.com/zh-tw/library/bb126445.aspx

應用程式可以在未安裝 Visual Studio 的電腦上執行。
若要建立執行階段範本,請將 [前置處理過的文字範本] 檔案加入專案中。 此外,您也可以加入純文字檔,並將其 [自訂工具] 屬性設定為 [TextTemplatingFilePreprocessor]。

2017年5月10日 星期三

LINQ - Sample Queries

https://code.msdn.microsoft.com/LINQ-Sample-Queries-13a42a54

This sample contains about 101 examples from each of these areas:

LINQ To Objects
LINQ To SQL
LINQ to DataSet
LINQ to Xml

DbContext和DbSet類別

不管透過哪種方式整合Entity Framework,關鍵還是在DbContext和DbSet這兩個類別

DbContext:
透過DbContext物件與資料進行連線溝通

DbSet:
利用DbSet物件封裝要處理的資料

Entity Framework 實務精要 第117頁

2017年5月7日 星期日

IPv4和IPv6資料庫定義的長度

http://stackoverflow.com/questions/3455320/size-for-storing-ipv4-ipv6-addresses-as-a-string

15 characters for IPv4 (xxx.xxx.xxx.xxx format, 12+3 separators)
39 characters (32 + 7 separators) for IPv6

2017年5月6日 星期六

HtmlHelper和UrlHelper差異

HtmlHelper用於產生超連結(a標籤)
UrlHelper只有輸出URL網址

HtmlHelper的ActionLink方法:
@Html.ActionLink("相簿", "Carousel", "Album")
 =>產生相簿超連結

UrlHelper的Action方法:
@Url.Action("Carousel", "Album")
 =>產生/Album/Carousel(只有文字,沒有超連結)

@Url.Action("Carousel", "Album", new { message = "3" })
 =>產生/Album/Carousel?message=3 (message 型別是string)

@Url.Action("Carousel", "Album", new { id = "3" })
 =>產生/Album/Carousel/3 (id型別是int)

Razor大括號程式區塊輸出文字


@:要輸出的文字

Razor的註解

@*我是註解*@

2017年5月5日 星期五

ViewData和ViewBag

ViewData:
可利用ViewData設定顯示在前端的資訊
在頁面中可以透過ViewData取得後端來的資料
ViewData只能對一個Action有作用
生命週期只存在於單一頁面,若網頁導向後,ViewData的資料會被清除

宣告
ViewData["Message"] = "Hello World";

使用
@ViewData["Message"]
=>會在頁面印出Hello World

ViewBag:
ViewBag和ViewData有一樣的功能,差別在ViewBag可動態產生屬性,利用dynamic這個型別包裝,使用ViewBag時不需再進行類別的轉換

宣告
ViewBag.Message = "Hello World";

使用
@ViewBag.Message
=>會在頁面印出Hello World

ViewData和ViewBag用途:
ViewData和ViewBag是用在Controller及View之間傳遞資料
如果要在Controller及Controller之間傳遞資料須使用TempData

ASP.NET MVC4.0實務專題範例教學 第6-15、6-17頁

2017年5月3日 星期三

SQL Server顯示執行的sql指令在哪一筆失敗

Get line number in file following TSQL error message
http://stackoverflow.com/questions/27785390/get-line-number-in-file-following-tsql-error-message


Invoke-SqlcmdEx
https://github.com/mnaoumov/Invoke-SqlcmdEx

Invoke-SqlcmdEx(Use LINENO approach)
https://github.com/mnaoumov/Invoke-SqlcmdEx/blob/LINENO/Invoke-SqlcmdEx.ps1

TempData和ViewData的差異

TempData預設會將資料存在Session,生命週期是一整個Request,即使網頁轉向還是可以取得資料

備註:TempData和ViewData皆是實作IDictionary介面

2017年5月2日 星期二

Microsoft.ReportViewer.WinForms

NuGet安裝
PM> Install-Package microsoft.ReportViewer.WinForms

Using the WinForms ReportViewer Control

https://docs.microsoft.com/en-us/sql/reporting-services/application-integration/using-the-winforms-reportviewer-control

RDLC、RDL和SSRS的差異

ReportViewer! RDLC!
http://blog.darkthread.net/post-2009-01-31-reportviewer-rdlc.aspx
滿不錯的介紹文章
英文原文: http://www.gotreportviewer.com

MICROSOFT® REPORT VIEWER 2012 RUNTIME

https://www.microsoft.com/zh-TW/download/details.aspx?id=35747

需要先安裝Microsoft SQL Server System CLR Types package
https://www.microsoft.com/zh-tw/download/details.aspx?id=35580
下載SQLSysClrTypes.msi


Generate class from database table



以Northwind的Customers為例,會產生以下程式碼
public class Customers
{
    public string CustomerID { get; set; }

    public string CompanyName { get; set; }

    public string ContactName { get; set; }

    public string ContactTitle { get; set; }

    public string Address { get; set; }

    public string City { get; set; }

    public string Region { get; set; }

    public string PostalCode { get; set; }

    public string Country { get; set; }

    public string Phone { get; set; }

    public string Fax { get; set; }

}

(T4)tt檔和cs檔之間傳遞變數資料

How do I pass a string parameter to a t4 template
http://stackoverflow.com/questions/15946802/how-do-i-pass-a-string-parameter-to-a-t4-template

(TSQL)組出DAOImpl.cs所需程式碼


(TSQL)組合出TRUNCATE TABLE等指令


2017年4月25日 星期二

=> Lambda運算子

https://msdn.microsoft.com/zh-tw/library/bb311046.aspx

它會在以方法語法所表示的 LINQ 查詢中大量使用
讀音:goes to
可以把它理解為一個匿名方法,Lambda表達式也是由匿名方法演變而來
C# 2.0的匿名方法用起來太麻煩
C# 3.0推出來Lambda表達式(Visual Studio 2008、.NET Framework 3.5)

C#
https://zh.wikipedia.org/wiki/C%E2%99%AF

Can I use Entity Framework 6 with Visual Studio 2010?

http://stackoverflow.com/questions/20993794/can-i-use-entity-framework-6-with-visual-studio-2010

EF6 tooling does not support VS2010. EF tooling was updated to work with EF6 for VS2012 and VS2013. In other words on VS2010 and EF6 you can do CodeFirst but not ModelFirst/DatabaseFirst.

2017年4月24日 星期一

輸出 Output

Ctrl+Alt+O

錯誤清單 Error List

Ctrl+\之後再按E

F4

屬性
Properties

Ctrl + Alt + S

伺服器總管
Server Explorer

Global.asax和App_Start

ASP.NET MVC 3將程式設定組態檔放在Global.asax(比如路由設定、過濾器)
ASP.NET MVC 4將其獨立出來到App_Start資料夾

2017年4月20日 星期四

查看Windows10安裝檔的版本資訊

需要系統管理權限
dism /Get-WimInfo /WimFile:H:\sources\install.esd /index:1

How to see which build and edition of Windows 10 the iso file contains



2017年4月18日 星期二

Windows Server關閉RC4和3DES加密演算法

RC 4
   
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 40/128]
        "Enabled"=dword:00000000
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 56/128]
        "Enabled"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128]
        "Enabled"=dword:00000000

3DES
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\Triple DES 168]
        "Enabled"=dword:00000000


Windows Server 2003、XP、Vista[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\Triple DES 168/168]
        "Enabled"=dword:00000000

2017年4月16日 星期日

Visual Studio編譯SCSS/LESS

Web Compiler
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler

Web Essentials 2015不再支援SCSS/LESS自動編譯
http://blog.darkthread.net/post-2015-07-21-web-compiler-for-vs2015.aspx

也可以另外安裝Prepros之類的獨立編譯工具

2017年3月21日 星期二

2017年3月20日 星期一

不使用GROUP BY去sum

use Northwind;

select OrderID,CustomerID,Freight,(select sum(Freight) from Orders) As 合計 from Orders;

select OrderID,CustomerID,Freight,sum(Freight) over ( partition by 1 ) As 合計 from Orders;

備註:如果使用
select OrderID,CustomerID,Freight,sum(Freight) from Orders會有以下錯誤訊息
訊息 8120,層級 16,狀態 1,行 1
Column 'Orders.OrderID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

UNIX2DOS 與 DOS2UNIX 批次轉換換行字元

http://blog.miniasp.com/post/2010/08/20/UNIX2DOS-DOS2UNIX-Windows-Linux-Convertion.aspx

2017年3月1日 星期三

Google Chart網頁圖表 + 後端 ASP.NET Web Form(ADO.NET)

http://ithelp.ithome.com.tw/articles/10176386

aspx的後置程式碼(cs)使用Javascript

ClientScriptManager.RegisterStartupScript 方法
https://msdn.microsoft.com/zh-tw/library/z9h4dk8y(v=vs.110).aspx

ref:
[Asp.Net]Page.ClientScript.RegisterStartupScript 和 Page.ClientScript.RegisterClientScriptBlock 之間的差異
http://wupeiting.blogspot.tw/2010/07/aspnetpageclientscriptregisterstartupsc.html

2017年2月28日 星期二

Page.MaintainScrollPositionOnPostBack 屬性

https://msdn.microsoft.com/zh-tw/library/system.web.ui.page.maintainscrollpositiononpostback(v=vs.110).aspx

取得或設定值,這個值表示是否要讓使用者在回傳後返回用戶端瀏覽器中的相同位置。 這個屬性會取代過時 SmartNavigation 屬性。

可以加在aspx或cs檔
也可以加在Web.config全站適用


ref:
如何讓網頁在 PostBack 後,回到原來停留的位置

讓Chrome瀏覽器支援MaintainScrollPositionOnPostback屬性


EnableSortingAndPagingCallbacks

GridView.EnableSortingAndPagingCallbacks 屬性
https://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.gridview.enablesortingandpagingcallbacks(v=vs.110).aspx

不能和select搭配使用
否則執行或有以下錯誤訊息:
啟用選取按鈕時 CommandField 不支援回呼,因為回呼中不會更新頁面上需依賴 'GridView1' 選取值才能呈現的其他控制項。請關閉 'GridView1' 上的回呼功能。


DataFormatString

{0:d} => 使用Windows的文化語系設定來呈現

{0:dd/MM/yyyy} =>使用自己設定的格式  (MM是大寫,MM會補0,M不補0)

中文 => {0:yyyy年MM月dd日}
星期幾 => {0:ddd}
時分秒 => {0:HH:mm:ss} (mm是小寫)


2017年2月27日 星期一

GridView是ASP.NET 2.0之後才有的

GridView是ASP.NET 2.0之後才有的,取代ASP.NET 1.X的DataGrid
和DetailsView、FormView不同之處,GridView沒有AutoGenerateInsertButton類似屬性,GridView要達成類似功能需搭配EmptyDataTemplate樣板(ASP.NET學習教材:使用C#第二版第9-9頁),把DefaultMode修改成Insert(第9-12頁)
GridView多了「樞紐分析表選取模式」

GridView的CRUD相關屬性:
 AutoGenerateDeleteButton、AutoGenerateEditButton、AutoGenerateSelectButton
https://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx

DetailsView的CRUD相關屬性:
AutoGenerateDeleteButton、AutoGenerateEditButton、AutoGenerateInsertButton
https://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.detailsview(v=vs.110).aspx

FormView的CRUD相關屬性
需使用Template,ItemTemplateEditItem TemplateInsertItem Template
在「FormView工作」(英文版:FormView Tasks)智慧標籤(Smart Tag)點選「編輯樣板」(英文版:Edit Templates)
https://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.formview(v=vs.110).aspx



2017年2月24日 星期五

GridView的ShowHeaderWhenEmpty屬性(無資料仍然顯示表頭)

ShowHeaderWhenEmpty屬性從.NET 4.0(Visual Studio 2010)之後出現
需和EmptyDataTemplate搭配使用

2017年2月20日 星期一

單選、複選

單選:
DropDownList
ListBox (SelectMode屬性為Single)
RadioButtonList


複選:
ListBox (SelectMode屬性為Multiple)
CheckBoxList

2017年2月17日 星期五

2017年2月15日 星期三

將Label的數字加總成金額輸出

int sum = Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text);
lblSum.Text = String.Format("{0:C}",sum);
//0表示第一個變數,也就是sum
//C表示Currency

//另一個寫法
//lblSum.Text = String.Format("{0:NT$ #,### ; -NT$ #,###}", sum);

AutoPostBack屬性

部分控制項才有這屬性
內容變更自動丟給Web Server
使用者不需要Submit

ASP.NET支援HTML5

從.NET 4.5和VS 2012開始

2017年2月12日 星期日

if(!Page.IsPostBack)

if(!Page.IsPostBack)表示第一次載入網頁才會執行
因為按下Button按鈕等會不斷地回傳,不斷地觸發Page_Load事件,所以要判斷

VB:
If Not Page.IsPostBack Then

Convert.ToInt32(Request["UID"])

int aid = Convert.ToInt32(Request["UID"]);

把使用者HttpRequest的 test.asxp?UID=7轉成int

Response.End()停止後面的程式碼執行

應該是類似WinForm的Application.Exit()吧?

.Redirect()和Server.Transfer()差異

.Redirect() => 可以導到其他網站

Server.Transfer() => 只能同一網站內

DetailsView和FormView的差別

DetailsView:
ASP.NET 2.0出現,畫面事先設計好,可以直接拿來使用

FormView:
以樣板(Template)為主,畫面上設計的彈性比較高

2017年1月14日 星期六

RegExp驗證小數點2位

^[0-9]+(.[0-9]{2})?$

demo:
https://regex101.com/r/CizAEg/1

RegExp驗證台灣手機門號10碼

^(?=.*[0])^(?=.*[9])(?=.*[0-9]).{10,10}$

demo:
https://regex101.com/r/3KRRPn/1

RegExp判斷密碼必須是6~7碼英數字(至少需要一個數字和一個英文字)

^(?=.*\d)(?=.*[a-zA-Z]).{6,7}$


Demo:
https://regex101.com/r/jza4od/1



使用 Regular Expression 驗證密碼複雜度
http://blog.miniasp.com/post/2008/05/09/Using-Regular-Expression-to-validate-password.aspx

參考保哥部落格寫法
  1. 至少有一個數字 => (?=.*\d)
  2. 至少有一個大寫或小寫英文字母 =>(?=.*[a-zA-Z])
  3. 至少有一個特殊符號 =>(?=.*\W) =>不是數字、字母、底線[azAZ09_]
  4. 字串長度在 6 ~ 30 個字母之間  =>.{6,30}
^(?=.*\d)(?=.*[a-zA-Z])(?=.*\W).{6,30}$
 demo:
https://regex101.com/r/Xobl5s/1

RegExp判斷五碼數字(郵遞區號5碼)

^\d{5}$

demo:
https://regex101.com/r/o2TPJ0/1


NNN|NNNNN
^[0-9]{3,3}|[0-9]{5,5}$
https://msdn.microsoft.com/zh-tw/library/partnercenter/dn974938.aspx

2017年1月2日 星期一

利用FileHelpers檢查csv格式


先把你的專案檔打開
在Visual Studio的套件管理器主控台輸入Install-Package FileHelpers



安裝完畢後,你的專案就會出現FileHelpers參考被引用、packages.config
 



如果無法使用Install-Package方式安裝
可以下載編譯好的DLL: FileHelpers_3.1.5_Build.zip (目前最新版本)
原始碼可以到該專案的Github下載
需要建立一個對映的Record Mapping Class
如果csv檔不符合對映就會出FileHelpers.BadUsageException





 


另一種處理CSV工具:CsvHelper
使用 CsvHelper - Part.2 資料讀取
http://kevintsengtw.blogspot.tw/2015/04/csvhelper-part2.html

REF:
How to validate a .csv file before storage in C#?
http://stackoverflow.com/questions/16608486/how-to-validate-a-csv-file-before-storage-in-c

How to validate CSV in C#?
http://stackoverflow.com/questions/24765492/how-to-validate-csv-in-c

C#判斷使用者輸入的本機路徑路徑是有效的

在stackoverflow看到的一片文章:Check if a string is a valid Windows directory (folder) path
可以使用Path.GetFullPath去判斷使用者輸入的本機路徑路徑是有效的
如果是無效的會丟出System.ArgumentException
只是空白字元算有效字元,如果怕使用者誤多輸入空白,可以自己判斷
if (inputPath.Contains(" ") )

Naming Files, Paths, and Namespaces
https://msdn.microsoft.com/en-us/library/aa365247
Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
  • The following reserved characters:
    • < (less than)
    • > (greater than)
    • : (colon)
    • " (double quote)
    • / (forward slash)
    • \ (backslash)
    • | (vertical bar or pipe)
    • ? (question mark)
    • * (asterisk)
  • Integer value zero, sometimes referred to as the ASCII NUL character.
  • Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
  • Any other character that the target file system does not allow.

What characters are forbidden in Windows and Linux directory names?
http://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names