編程技巧:.Net Framework_.Net教程
推薦:存儲過程編寫經驗和優化措施介紹:在數據庫的開發過程中,經常會遇到復雜的業務邏輯和對數據庫的操作,這個時候就會用SP來封裝數據庫操作。如果項目的SP較多,書寫又沒有一定的規范,將會影響以后的系統維護困難和大SP邏輯
.Net Framework
1. 如何獲得系統文件夾
使用System.Envioment類的GetFolderPath方法;例如:
Environment.GetFolderPath( Environment.SpecialFolder.Personal )
2. 如何獲得正在執行的exe文件的路徑
1) 使用Application類的ExecutablePath屬性
2) System.Reflection.Assembly.GetExecutingAssembly().Location
3. 如何檢測操作系統的版本
使用Envioment的OSVersion屬性,例如:
OperatingSystem os = Environment.OSVersion;
MessageBox.Show(os.Version.ToString());
MessageBox.Show(os.Platform.ToString());
4. 如何根據完整的文件名獲得文件的文件名部分
使用System.IO.Path類的方法GetFileName或者GetFileNameWithoutExtension方法
5. 如何通過文件的全名獲得文件的擴展名
使用System.IO.Path.GetExtension靜態方法
6. Vb和c#的語法有什么不同click here
7. 如何獲得當前電腦用戶名,是否聯網,幾個顯示器,所在域,鼠標有幾個鍵等信息
使用System.Windows.Forms. SystemInformation類的靜態屬性
8. 修飾Main方法的[STAThread]特性有什么作用
標示當前程序使用單線程的方式運行
9. 如何讀取csv文件的內容
通過OdbcConnection可以創建一個鏈接到csv文件的鏈接,鏈接字符串的格式是:"Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=" cvs文件的文件夾路徑 " Extensions=asc,csv,tab,txt; Persist Security Info=False";
創建連接之后就可以使用DataAdapter等存取csv文件了。
詳細信息見此處
10. 如何獲得磁盤開銷信息,代碼片斷如下,主要是調用kernel32.dll中的GetDiskFreeSpaceEx外部方法。
public sealed class DriveInfo
{
[DllImport("kernel32.dll", EntryPoint = "GetDiskFreeSpaceExA")]
private static extern long GetDiskFreeSpaceEx(string lpDirectoryName,
out long lpFreeBytesAvailableToCaller,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes);
public static long GetInfo(string drive, out long available, out long total, out long free)
{
return GetDiskFreeSpaceEx(drive, out available, out total, out free);
}
public static DriveInfoSystem GetInfo(string drive)
{
long result, available, total, free;
result = GetDiskFreeSpaceEx(drive, out available, out total, out free);
return new DriveInfoSystem(drive, result, available, total, free);
}
}
public struct DriveInfoSystem
{
public readonly string Drive;
public readonly long Result;
public readonly long Available;
public readonly long Total;
public readonly long Free;
public DriveInfoSystem(string drive, long result, long available, long total, long free)
{
this.Drive = drive;
this.Result = result;
this.Available = available;
this.Total = total;
this.Free = free;
}
}
可以通過DriveInfoSystem info = DriveInfo.GetInfo("c:");來獲得指定磁盤的開銷情況
11.如何獲得不區分大小寫的子字符串的索引位置
1)通過將兩個字符串轉換成小寫之后使用字符串的IndexOf方法:
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// The line below will return -1 when expected is 4.
int i = strParent.IndexOf(strChild);
// The line below will return proper index
int j = strParent.ToLower().IndexOf(strChild.ToLower());
2) 一種更優雅的方法是使用System.Globalization命名空間下面的CompareInfo類的IndexOf方法:
using System.Globalization;
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// We create a object of CompareInfo class for a neutral culture or a culture insensitive object
CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
int i = Compare.IndexOf(strParent,strChild,CompareOptions.IgnoreCase);
分享:無刷新仿google波形扭曲彩色Asp.net驗證碼網上關于Asp.net驗證碼的示例是在不少,前一段時間我發布的《51aspx實現的Asp.net無刷新中文驗證碼》受到了廣大網站的轉載,但是關于其中無刷新及波形扭曲的文章寥寥無幾,示例也幾乎難尋,于是
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發送Email實例(可帶附件)
- js實現廣告漂浮效果的小例子
- asp.net Repeater 數據綁定的具體實現
- Asp.Net 無刷新文件上傳并顯示進度條的實現方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數據庫(連接字符串的配置及獲取)
- asp.net頁面傳值測試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現分頁示例代碼
- 相關鏈接:
- 教程說明:
.Net教程-編程技巧:.Net Framework
。