Phần 1: Yêu cầu Viết chương trình có cài đặt danh sách liên kết vòng, nội dung của nút là số nguyên, chương trình có…
Xem thêm Cài đặt danh sách vòng đơn bằng C#Category: C#
Cài đặt danh sách liên kết bằng ngôn ngữ C#
Phần 1: Cài đặt danh sách liên kết, viết các hàm thực hiện: Tính số lượng các nút của danh sách. Cho thêm con trỏ…
Xem thêm Cài đặt danh sách liên kết bằng ngôn ngữ C#Code C# send mail with Gmail SMTP server
Bạn đang cần code C# thực hiện gửi mail với giao thức smpt của gmail? Để thực hiện gửi mail bằng gmail trong C# chúng…
Xem thêm Code C# send mail with Gmail SMTP serverCopy folder in C#
Nếu bạn đang tìm code c# thực hiện copy thư mục thì đây, ngay bên dưới đây là code bạn cần nhé!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private void DirectoryCopy(string sourceDir, string destDir) { DirectoryInfo dir = new DirectoryInfo(sourceDir); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw new DirectoryNotFoundException( "Không tìm thấy thư mục: " + sourceDir); } if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { string temppath = Path.Combine(destDir, file.Name); file.CopyTo(temppath,true); } foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destDir, subdir.Name); DirectoryCopy(subdir.FullName, temppath); } } |
Trong đó:…
Xem thêm Copy folder in C#Sleep in C#
Nếu bạn đang viết một ứng dụng với ngôn ngữ C#. Và muốn cho ứng dụng ngủ 1 vài mili giây thì đây là code…
Xem thêm Sleep in C#Access connection string in C#
1 2 |
//using System.Data.OleDb; string m_ConnectString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=file_path.mdb;"; |
nosomovo
Xem thêm Access connection string in C#Mysql connection string in C#
1 |
string Connectionstring = "SERVER=" + m_Server + "; PORT=" + m_Port + ";" + " DATABASE=" + m_Database + ";" + "UID=" + m_UserName + ";" + "PASSWORD=" + m_PassWord + "; CharSet=utf8; POOLING=TRUE;"; |
nosomovo
Xem thêm Mysql connection string in C#Excel connection string in C#
1 |
string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + "filename" + "; Extended Properties=\"Excel 12.0\";"; |
Nosomovo
Xem thêm Excel connection string in C#Sql server connection string in C#
Kết nối bằng quyền Windows:
1 |
string m_ConnectString = "Data Source=" + "servername" + ";Initial Catalog=" + "databasename" + ";Integrated Security=True;"; |
Kết nối bằng quyền User:
1 |
string m_ConnectString = "Data Source=" + "servername" + ";Initial Catalog=" + "databasename" + ";User Id=" + "username" + ";Password=" + "pasword" + ";"; |
Nosomovo
Xem thêm Sql server connection string in C#Code C# – Upload file to web server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
public class HttpUploadHelper { private HttpUploadHelper() { } public static string Upload(string url, UploadFile[] files, NameValueCollection form) { HttpWebResponse resp = Upload((HttpWebRequest)WebRequest.Create(url), files, form); using (Stream s = resp.GetResponseStream()) using (StreamReader sr = new StreamReader(s)) { return sr.ReadToEnd(); } } public static HttpWebResponse Upload(HttpWebRequest req, UploadFile[] files, NameValueCollection form) { List<MimePart> mimeParts = new List<MimePart>(); try { foreach (string key in form.AllKeys) { StringMimePart part = new StringMimePart(); part.Headers["Content-Disposition"] = "form-data; name=\"" + key + "\""; part.StringData = form[key]; mimeParts.Add(part); } int nameIndex = 0; foreach (UploadFile file in files) { StreamMimePart part = new StreamMimePart(); if (string.IsNullOrEmpty(file.FieldName)) file.FieldName = "file" + nameIndex++; part.Headers["Content-Disposition"] = "form-data; name=\"" + file.FieldName + "\"; filename=\"" + file.FileName + "\""; part.Headers["Content-Type"] = file.ContentType; part.SetStream(file.Data); mimeParts.Add(part); } string boundary = "----------" + DateTime.Now.Ticks.ToString("x"); req.ContentType = "multipart/form-data; boundary=" + boundary; req.Method = "POST"; long contentLength = 0; byte[] _footer = Encoding.UTF8.GetBytes("--" + boundary + "--\r\n"); foreach (MimePart part in mimeParts) { contentLength += part.GenerateHeaderFooterData(boundary); } req.ContentLength = contentLength + _footer.Length; byte[] buffer = new byte[8192]; byte[] afterFile = Encoding.UTF8.GetBytes("\r\n"); int read; using (Stream s = req.GetRequestStream()) { foreach (MimePart part in mimeParts) { s.Write(part.Header, 0, part.Header.Length); while ((read = part.Data.Read(buffer, 0, buffer.Length)) > 0) s.Write(buffer, 0, read); part.Data.Dispose(); s.Write(afterFile, 0, afterFile.Length); } s.Write(_footer, 0, _footer.Length); } return (HttpWebResponse)req.GetResponse(); } catch { foreach (MimePart part in mimeParts) if (part.Data != null) part.Data.Dispose(); throw; } } } |
nosomovo
Xem thêm Code C# – Upload file to web serverCode C# – Thao tác với Registry của windows
Lớp myRegistry bên dưới cung cấp cho ta các hàm thao tác với Registry của windows như: Đọc giá trị của 1 key. Đăng ký key và…
Xem thêm Code C# – Thao tác với Registry của windowsCode C# – Thực hiện các phép toán trên tập hợp
Lớp Set bên dưới sẽ cung cấp cho chúng ta các hàm thực hiện các phép toán trên tập hợp như: Giao, hợp, hiệu:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
class Set { private string m_Set = ""; #region Contructors public Set(string str_set) { this.m_Set = str_set; } #endregion #region Properties public string SET { get { return m_Set; } set { m_Set = value; } } public int SIZE { get { return this.m_Set.Split(new char[1] { ',' }).Length; } } #endregion #region Method /// <summary> /// Giao 2 tập hợp /// </summary> /// <param name="Set2"></param> /// <returns>Kết quả của phép giao 2 tập hợp</returns> public string Intersection(Set Set2) { string[] arr_Set1 = this.m_Set.Split(new char[1] { ',' }); string[] arr_Set2 = Set2.SET.Split(new char[1] { ',' }); string Resualt = ""; foreach (string item1 in arr_Set1) foreach (string item2 in arr_Set2) if (item1 == item2) Resualt += item1 + ","; if (Resualt.Length > 0) Resualt = Resualt.Substring(0, Resualt.Length - 1); return Resualt; } /// <summary> /// Hợp 2 tập hợp /// </summary> /// <param name="Set2"></param> /// <returns>Kết quả của phép hợp 2 tập hợp</returns> public string Union(Set Set2) { string[] arr_Set1 = this.m_Set.Split(new char[1] { ',' }); string[] arr_Set2 = Set2.SET.Split(new char[1] { ',' }); string Resualt = ""; if (this.IsNull()) Resualt = Set2.SET; else if (Set2.IsNull()) Resualt = this.SET; else { Resualt = this.SET + ","; foreach (string item2 in arr_Set2) { bool exits = false; foreach (string item1 in arr_Set1) { if (item1 == item2) { exits = true; break; } } if (exits == false) Resualt += item2 + ","; } if (Resualt.Length > 0) Resualt = Resualt.Substring(0, Resualt.Length - 1); } return Resualt; } /// <summary> /// Hiệu 2 tập hợp /// </summary> /// <param name="Set2"></param> /// <returns>Kết quả hiệu 2 tập hợp</returns> public string Minus(Set Set2) { string[] arr_Set1 = this.m_Set.Split(new char[1] { ',' }); string[] arr_Set2 = Set2.SET.Split(new char[1] { ',' }); string Resualt = ""; foreach (string item1 in arr_Set1) { bool exits = false; foreach (string item2 in arr_Set2) { if (item1 == item2) { exits = true; break; } } if (exits == false) Resualt += item1 + ","; } if (Resualt.Length > 0) Resualt = Resualt.Substring(0, Resualt.Length - 1); return Resualt; } /// <summary> /// Kiểm tra tập hợp có là tập rỗng hay không? /// </summary> /// <returns></returns> public bool IsNull() { bool resualt = true; if (this.m_Set.Length > 0) resualt = false; return resualt; } #endregion } |
…
Xem thêm Code C# – Thực hiện các phép toán trên tập hợp