转自:http://tmsoft.lsxy.com/index.php?load=read&id=224
2.引用Microsoft.VisualBasic 命名空间
3.所有的My对象应用皆出自以下类库,本文仅抛砖引玉,更多请大家看MSDN
4.应用-获取应用程序所在服务器信息
说明:要添加using Microsoft.VisualBasic.Devices;
代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Computer();
TextBox1.Text = "机器名为:" + my.Name + "\r\n";
TextBox1.Text += "操作系统信息为:" + my.Info.OSFullName +" "+my.Info.OSPlatform+" "+my.Info.OSVersion +"\r\n";
TextBox1.Text += "物理内存为:" + my.Info.TotalPhysicalMemory + "\r\n";
TextBox1.Text += "虚拟内存为:" + my.Info.TotalVirtualMemory + "\r\n";
TextBox1.Text += "可用物理内存为:" + my.Info.AvailablePhysicalMemory + "\r\n";
TextBox1.Text += "可用虚拟内存为:" + my.Info.AvailableVirtualMemory + "\r\n"; }
}
代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Microsoft.VisualBasic.Devices.Computer();
TextBox1.Text = my.FileSystem.ReadAllText(FileUpload1.PostedFile.FileName,Encoding.GetEncoding("gb2312"));
}
}
代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Microsoft.VisualBasic.Devices.Computer();
foreach (String k in my.Registry.CurrentUser.GetSubKeyNames())
{
TextBox1.Text += k + "\r\n";
}
}
}
可以Registry后点出ClassesRoot,LocalMachine等节点请自己尝试。
7.Microsoft.VisualBasic命名空间的字符串处理能力非常强大。
最常见的半角和全角互换,简体和繁体互换等等做起来非常轻松,既然可以这么轻松处理为什么要写很复杂的类呢?
代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = Strings.StrConv(TextBox1.Text, VbStrConv.Narrow, 0);
TextBox4.Text = Strings.StrConv(TextBox3.Text, VbStrConv.TraditionalChinese, 0);
}
}
VbStrConv.None |
不执行任何转换 |
VbStrConv.LinguisticCasing |
使用语言规则进行大小写,而不使用文件系统(默认)。仅当与 VbStrConv.UpperCase 和 VbStrConv.LowerCase 一起使用时才有效。 |
VbStrConv.UpperCase |
将字符串转换为大写字符。 |
VbStrConv.LowerCase |
将字符串转换为小写字符。 |
VbStrConv.ProperCase |
将字符串中每个单词的第一个字母转换为大写。 |
VbStrConv.Wide * |
将字符串中的窄(半角)字符转换为宽(全角)字符。 |
VbStrConv.Narrow * |
将字符串中的宽(全角)字符转换为窄(半角)字符。 |
VbStrConv.Katakana ** |
将字符串中的平假名字符转换为片假名字符。 |
VbStrConv.Hiragana ** |
将字符串中的片假名字符转换为平假名字符。 |
VbStrConv.SimplifiedChinese * |
将繁体中文字符转换为简体中文字符。 |
VbStrConv.TraditionalChinese * |
将简体中文字符转换为繁体中文字符。 |