收 藏 投 稿 繁 体 RSS 
站长吧-中国站长学习与交流的网站
首 页 运 营 学 院 建 站 论 坛
Web master8.net  
 网站运营  
  欢迎在本站发布信息,在线投递稿件请点这里。编辑QQ:4908220,欢迎联系交流。
业界动态 创业故事 推广研究 策划盈利 电子商务 企业平台
  站长工具
SEO查询 Whois查询 Pr查询 域名查询 IP查询 网页编辑器
 建站服务  
  如有建站意向,请尽快联系我们,以便安排时间... 建站服务 QQ4908220 QQ:4908220
作品展示 服务范围 服务流程 服务报价 联系方式 付款方式
文章正文  » 您的当前位置: 首页 >> 学院 >> 程序开发 >> ASP.Net
编程技巧:.Net Framework
  来源:互联网 | 时间:2007-05-13 | 浏览:   相关评论 | 报告错误 | 发布文章
【字号: | | 】 【背景色 杏仁黄 秋叶褐 胭脂红 芥末绿 天蓝 雪青 灰 银河白(默认色)

.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);

zxiao_11
  • 上一篇:关于行业网站的运营建议
  • 下一篇:Skype出台海外赔偿方案

  • 我要投稿  打印本文  推荐本文  加入收藏  返回顶部  关闭窗口
    搜模板(www.somoban.com) 原创网站模板交易平台
    阿里妈妈再掀疯狂采购风,网站广告位严重告急,急召天下站长
    基于PHP+MySQL的整站、模块、插件开发等或者按需求实现相应功能;
基于各PHP主流建站系统CMS,BBS,BLOG等的模板定制,完全手写代码;
整站数据迁移或备份恢复;网页代码优化、重构;整站常规SEO优化;网站技术支持;
点击了解详情...
    站长论坛
    • 验证码: