C#中一般是可以利用WebClient类和WebRequest类获取网页源代码。下面分别说明这两种方法的实现。 WebClient类获取网页源代码 WebClient类 WebClient类位于System.Net命名空间下,WebClient类提供向URI标识的任何本地、Intranet或Internet资源发送数据以及从这些资源接收数据的公共方法。 源代码 ///引用命名空间 using System.IO; using System.Net; using System.Text; PageUrl = "....
// 获取程序的基目录。 System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径。 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName // 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。 System.Environment.CurrentDirectory // 获取应用程序的当前工作目录。 System.IO.Directory.GetCurrentDirectory() // 获取和设置包括该应用程序的目录的名称。 System.AppDomain.CurrentDomain...
原文:C#获取CPU和内存使用率获取内存使用率方式1:using System; using System.Runtime.InteropServices;namespace ConsoleApp1 {publicclass Class1{staticvoid Main(string[] args){Console.WriteLine("总内存:" + FormatSize(GetTotalPhys()));Console.WriteLine("已使用:" + FormatSize(GetUsedPhys()));Console.WriteLine("可使用:" + FormatSize(GetAvailPhys()));Console.ReadKey();}#region 获得内存信息API[DllImport(...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Text.RegularExpressions; using System.IO; using System.Runtime.InteropServices;namespace pandian.cs {publicclass UpdateDateTime{publicstatic DateTime dt = DateTime.Now;publicstaticvoid UpdateTime(){try{Uri uri = new Uri("http://www.beijing-time.org/time15.asp");System.Windows.Forms....
http://www.educity.cn/develop/495493.html 有时需要在JavaScript中获取后台变量的值,来判断JavaScript的执行逻辑,或者需要调用C#后台方法获取数据,我们可以使用<%= %>表达式很容易地实现,<%= %>主要是对表达式进行绑定,并计算表达式的值。 1.JavaScript获取后台变量。在后台声明一个全局变量,并将变量的访问属性设置为protected或public,就可以在页面使用了。 在后台C#代码中声明一个protected或public类型的变量...
//获取当前进程的完整路径,包含文件名(进程名)。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#获取程序集的版本号:string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); C#中如何将记录项目的最后编译时间:在实际的软件开发工作中,我们通常需要记录某个工程的最后编译时间,原来在C++中,我们有个__DATE__,__TIME__,__FILE__,__LINE__这样的异性宏定义可以使用,但是在C#中,不能使用,但是可以用以下语句来获得最后编译时间。System.IO.File.GetLastWriteTime(this.GetTy...
原文:http://www.cnblogs.com/ingstyle/p/4380794.html
/// <summary>/// 远程获取页面数据/// </summary>/// <param name="Url">地址</param>/// <returns></returns>public static string GetHttpData(string Url){//string sException = null;string sRslt = null;WebResponse oWebRps = null;WebRequest oWebRqst = WebRequest.Create(Url);oWebRqst.Timeout = 50000;//try//{oWebRps = oWebRqst.GetResponse();//}//catch (WebException e)//{// sException = e.Message.ToStrin...
C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径。 2. System.Environment.CurrentDirectory -获取和设置当前目录(该进程从中启动的目录)的完全限定目录。 3. System.IO.Directory.GetCurrentDirectory() -获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或...
XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(System.Web.HttpUtility.UrlDecode(mCuTable.DATASOURCE)); sDataSourceName = xDoc.SelectNodes("datasource/dataset")[0].Attributes["id"].Value; sDatasetType = xDoc.SelectNodes("datasource/dataset")[0].Attributes["type"].Value;View Code原文:http://www.cnblogs.com/zecVip/p/4757929.html
1protectedvoid ExportExcel(System.Data.DataTable dt)2 {3if (dt == null || dt.Rows.Count == 0) return;4 Microsoft.Office.Interop.Excel.Application xlsxApp = new Application();5if (xlsxApp == null) return;6//System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;7//System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.Cu...
有时候,我们用paint重绘用户控件时,起不到作用,这个时候,我们可以通过获取进程,来重绘控件。下面这个实例是重绘边框的颜色为红色,当边框的风格为FixedSingle的时候,来进行重绘操作。 /// <summary> /// 获得当前进程,以便重绘控件 /// </summary> /// <param name="hWnd"></param> /// <returns></returns> [System.Runtime.InteropServices.DllImport("user32.dll")]static extern IntPtr GetWindowDC(IntPtr hWnd);[Syst...
原文:C# Winform 中如何获取本机安装输入法,并设置为默认输出语言,如何打开搜狗输入法和手写板一、问题:今天,我整理了一下两个问题1、如何获取本机安装所有输入法,并设置为系统输出语言2、如何打开搜狗拼音输入法工具栏和手写板:二、解决方法比如:我们要设置搜狗输入法为本机输入语言,要怎么用代码实现呢?//获取所有安装的输入法InputLanguageCollection langs = InputLanguage.InstalledInputLanguages;//循环遍历输入法集...
一、不用SQLHelper.cs等帮助类1.获取Return返回值 程序代码 存储过程Create PROCEDURE MYSQL @a int, @b intAS return @a + @bGOSqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());conn.Open();SqlCommand MyCommand = new SqlCommand("MYSQL", conn);MyCommand.CommandType = CommandType.StoredProcedure;MyCommand.Parameters.Add(new SqlParameter("@a", SqlD...