【【c#】 使用Directory.GetFiles获取局域网中任意电脑指定文件夹下的文件】教程文章相关的互联网学习教程文章

C#获取类以及类下的方法(用于Asp.Net MVC)【代码】

在开发MVC项目中遇到的问题,做权限控制时,通过MVC的过滤器来实现,所以在分配权限时希望获取到所有的控制器和Action方法,通过查找资料,参考了《Asp.Net MVC框架揭秘》,最终实现。在C#中,实现动态获取类和方法主要通过反射来实现,要引用System.Reflection。public ActionResult GetControllerAndAction()List<Type> controllerTypes = new List<Type>(); //创建控制器类型列表var assembly = Assembly.Load("MySoft.UI");...

【C#】获取硬盘的型号,一般加密软件的手段【代码】

需要引用的DLL:System.Management需要使用的命名空间:using System.Management;//需要用到的类://ManagementObject:WMI对象//ManagementObjectSearcher:查询管理信息//ManagementObjectSearcher.Get("查询语句"),返回结果集合//PropertyData来的value属性string hard = "";//创建ManagementObjectSearcher对象ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");ManagementObje...

C# 获取当前日期时间【代码】

C#获取时间//获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToString(); // 2008-9-4 20:12:12 //获取日期 DateTime.Now.ToLongDateString().ToString(); // 2008年9月4日 DateTime.Now.ToShortDateString().ToString(); // 2008-9-4 DateTime.Now.ToString("yyyy-MM-dd"); // 2008-09-04 DateTime.Now.Date.ToString(); // 2008-9-4 0:00:...

c# 通过按钮获取文件夹和打开磁盘文件【代码】

Button控件获取文件夹:1 FolderBrowserDialog fileDialog = new FolderBrowserDialog(); 2if (fileDialog.ShowDialog() == DialogResult.OK) 3 { 4 MessageBox.Show(fileDialog.SelectedPath); 5 }Button打开磁盘文件夹: 1 System.Diagnostics.Process.Start("explorer.exe", FilePath); 原文:http://www.cnblogs.com/hbtmwangjin/p/7602807.html

c# 获取二维数组的行数和列数

static void Main(string[] args) { int[,] arr = new int[3, 3] { { 1, 1, 1 }, { 2, 2, 2 }, { 3, 3, 3 } }; Console.WriteLine("行数:" + arr.Rank); Console.WriteLine("列数:" + (arr.GetUpperBound(arr.Rank - 1) + 1)); Console.ReadKey(); }原文:http://www.cnblogs.com/BeeSnow/p/7979332.html

C# WinForm获取当前路径汇总

//获取当前进程的完整路径,包含文件名(进程名)。string str = this.GetType().Assembly.Location;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)//获取新的Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)//获取和设置当前目录(即...

C# 笔记 获取程序当前目录【代码】

在C#中,我们有以下几种方式获取程序当前目录: Console.WriteLine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);Console.WriteLine(System.Environment.CurrentDirectory);Console.WriteLine(System.IO.Directory.GetCurrentDirectory());Console.WriteLine(Environment.CurrentDirectory);输出:D:\MyTool\MyWorkR...

C#获取当前运行的源代码的文件名和当前源代码的行数的方法【图】

1,.声明:本文转载自http://www.cnblogs.com/lvdongjie/p/5777330.html2.工程代码: class Program { static void Main(string[] args) { Console.WriteLine(GetCurSourceFileName()+ ","+GetLineNum()); Console.ReadLine(); } /// 取得当前源码的哪一行 /// </summary> /// <returns></returns> public static int GetLineNum() { S...

C#用正则表达式 获取网页源代码标签的属性或值【代码】

原文地址:http://blog.csdn.net/lhfly/article/details/7684319 整理两个 在C#中,用正则表达式 获取网页源代码标签的属性或值的方法 :1、获取标签中的值: <a href="www.csdn.net" class="main" >CSDN</a> 结果:CSDN///<summary>/// 获取字符中指定标签的值///</summary>///<param name="str">字符串</param>///<param name="title">标签</param>///<returns>值</returns>publicstaticstring GetTitleContent(string str, stri...

C#获取CPU占用率、内存占用、磁盘占用、进程信息【代码】

using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; using System.IO; using System.Text; using System.Management; using System.Runtime.InteropServices; namespace Lemony.SystemInfo { /// /// 系统信息类 - 获取CPU、内存、磁盘、进程信息 /// public class SystemInfo { private int m_ProcessorCount = 0; //CPU个数 private PerformanceCounter pcCpuLoad...

C# 获取本机CPU序列号,MAC地址,硬盘ID,本机IP地址,计算机名,物理内存,PC类型【代码】【图】

首先引入服务 然后 调用本文转载自http://blog.sina.com.cn/s/blog_7eeb43210101hf7f.html publicclass Computer{publicstaticstring CpuID; //1.cpu序列号publicstaticstring MacAddress; //2.mac序列号publicstaticstring DiskID; //3.硬盘idpublicstaticstring IpAddress; //4.ip地址publicstaticstring LoginUserName; //5.登录用户名publicstaticstring ComputerName; //6.计算机名publicstaticstring SystemType; //7.系统类...

C#获取程序代码执行时长【代码】

ArrayList list = new ArrayList();long startTicks = DateTime.Now.Ticks;for (int i = 0; i < 1000000; i++){list.Add(i);}for (int i = 0; i < 1000000; i++){int value = (int)list[i];}long endTicks = DateTime.Now.Ticks;Console.WriteLine("arrayList执行时长:" + (endTicks-startTicks));List<int> list2 = new List<int>();long startTicks1 = DateTime.Now.Ticks;for (int i = 0; i < 1000000; i++){list2.Add(i);}for...

c#获取当前应用程序所在路径【图】

一、获取当前文件的路径1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包括文件名。2. System.Environment.CurrentDirectory 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。3. System.IO.Directory.GetCurrentDirectory() 获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:/www里,这个函数有可能返回C:/Documents a...

C#中获取随机数有三种方法

随机数的定义为:产生的所有数字毫无关系.在实际应用中很多地方会用到随机数,比如需要生成唯一的订单号.在C#中获取随机数有三种方法: 一.Random 类Random类默认的无参构造函数可以根据当前系统时钟为种子,进行一系列算法得出要求范围内的伪随机数.12Random rd = new Random();int i = rd.Next();这种随机数可以达到一些要求较低的目标,但是如果在高并发的情况下,Random类所取到的系统时钟种子接近甚至完全一样,就很有可能出现重复,这...

C#中如何获取一个二维数组的两维长度,即行数和列数?以及多维数组各个维度的长度?【代码】

如何获取二维数组中的元素个数呢?int[,] array = new int[,] {{1,2,3},{4,5,6},{7,8,9}};//定义一个3行3列的二维数组int row = array.Rank;//获取维数,这里指行数int col = array.GetLength(1);//获取指定维度中的元素个数,这里也就是列数了。(0是第一维,1表示的是第二维)int col = array.GetUpperBound(0)+1;//获取指定维度的索引上限,在加上一个1就是总数,这里表示二维数组的行数int num = array.Length;//获取整个二维数...