Skip to content

Instantly share code, notes, and snippets.

View longtth's full-sized avatar

Long NguyenX longtth

View GitHub Profile
public void WriteToFile(string filePath, List<Honda2ObjFinal> list)
{
string json = JsonConvert.SerializeObject(list, Formatting.Indented);
// cái đoạn code dùng StreamWriter này éo biết vì sao sẽ hỏng đi 300 line cuối cùng.
//FileStream fs = new FileStream(filePath, FileMode.CreateNew);
//Encoding utf8WithoutBom = new UTF8Encoding(false);
//StreamWriter sw = new StreamWriter(fs, utf8WithoutBom);
//sw.Write(json);
@longtth
longtth / FileDirChecker.cs
Last active February 23, 2018 10:18
C# Check path is a file or dir
public class FileDirChecker
{
public bool isDirectory(string path)
{
bool ret = false;
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(path);
if (attr.HasFlag(FileAttributes.Directory))
ret = true;
public class FileDirChecker
{
public bool isDirectory(string path)
{
bool ret = false;
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(path);
if (attr.HasFlag(FileAttributes.Directory))
ret = true;
/// <summary>
/// Provides methods for Serialization and Deserialization of XML/Extensible Markup Language documents.
/// </summary>
public class XmlSerialization
{
/// <summary>
/// Serializes an object to an XML/Extensible Markup Language string.
/// </summary>
/// <typeparam name="T">The type of the object to serialize.</typeparam>
/// <param name="value">The object to serialize.</param>
/// <summary>
/// Provides methods for Serialization and Deserialization of JSON/JavaScript Object Notation documents.
/// </summary>
public class JsonSerialization
{
/// <summary>
/// Serializes an object to a JSON/JavaScript Object Notation string.
/// </summary>
/// <typeparam name="T">The type of the object to serialize.</typeparam>
/// <param name="value">The object to serialize.</param>
For i=1 to n { // file count là n=1000
Xử lí file thứ i
Hiển thị label "1/n đang dc xử lí"
Application.DoEvents();
}
@longtth
longtth / VideoReaderForm.cs
Created May 7, 2018 03:49
Đọc file video
using DAL;
using Emgu.CV;
using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
@longtth
longtth / DirSearchRecursively.cs
Created May 11, 2018 03:22
Đọc tất cả file trong tất cả sub-folder.
static void DirSearch(string sDir)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
Console.WriteLine(f);
}
@longtth
longtth / ListToDataTable.cs
Created May 16, 2018 06:09
List<T> to DataTable
IEnumerable<SomeType> data = ...
DataTable table = new DataTable();
using(var reader = ObjectReader.Create(data)) {
table.Load(reader);
}
IEnumerable<SomeType> data = ...
DataTable table = new DataTable();
using(var reader = ObjectReader.Create(data, "Id", "Name", "Description")) {
table.Load(reader);
@longtth
longtth / DataGridViewFilter.cs
Created May 18, 2018 04:42
DataGridView filter
DataView dv;
dv = new DataView(ds.Tables[0], "type = 'business' ", "type Desc", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;