using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Windows.Forms.Design; using System.DirectoryServices; using System.Reflection; using System.Text.RegularExpressions; int TotalServerCount=0; DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC"); //TotalServerCount=rootfolder.Children.SchemaFilter.Count; foreach (DirectoryEntry child in rootfolder.Children) { if (child.SchemaClassName == "IIsWebServer") { TotalServerCount+=1; } } //循环获取所有站点详细属性写入数组中 string [] arrayServerID = new string[TotalServerCount];//站点标识符 string [] arrayServerIP = new string[TotalServerCount];//站点主机头 string [] arrayServerPort = new string[TotalServerCount];//站点主机头 string [] arrayServerHeader = new string[TotalServerCount];//站点主机头 string [] arrayServerPath = new string[TotalServerCount];//站点主机头 string [] arrayServerComment = new string[TotalServerCount];//站点主机头 string [] arrayServerBinds = new string[TotalServerCount];//站点主机头 string currentServerBindings;//绑定主机头IP端口字符串 char[] a=":".ToCharArray(); string […]
View DetailsC# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 1.数组是固定大小的,不能伸缩。虽然System.Array.Resize这个泛型方法可以重置数组大小, 但是该方法是重新创建新设置大小的数组,用的是旧数组的元素初始化。随后以前的数组就废弃!而集合却是可变长的 2.数组要声明元素的类型,集合类的元素类型却是object. 3.数组可读可写不能声明只读数组。集合类可以提供ReadOnly方法以只读方式使用集合。 4.数组要有整数下标才能访问特定的元素,然而很多时候这样的下标并不是很有用。集合也是数据列表却不使用下标访问。 很多时候集合有定制的下标类型,对于队列和栈根本就不支持下标访问! //数组 int[] intArray1; //初始化已声明的一维数组 intArray1 = new int[3]; intArray1 = new int[3]{1,2,3}; intArray1 = new int[]{1,2,3}; //ArrayList类对象被设计成为一个动态数组类型,其容量会随着需要而适当的扩充 方法 1:Add()向数组中添加一个元素, 2:Remove()删除数组中的一个元素 3:RemoveAt(int i)删除数组中索引值为i的元素 4:Reverse()反转数组的元素 5:Sort()以从小到大的顺序排列数组的元素 6:Clone()复制一个数组 //List 可通过索引访问的对象的强类型列表。提供用于对列表进行搜索、排序和操作的方法 在决定使用 List 还是使用 ArrayList 类(两者具有类似的功能)时,记住 List 类在大多数情况下执行得更好并且是类型安全的。如果对 List 类的类型 T 使用引用类型,则 两个类的行为是完全相同的。但是,如果对类型 T 使用值类型,则需要考虑实现和装箱问题。 如果对类型 T 使用值类型,则编译器将特别针对该值类型生成 List 类的实现。这意味着不必对 List 对象的列表元素进行装箱就可以使用该元素,并且在创建大约 500 个列表 元素之后,不对列表元素装箱所节省的内存将大于生成该类实现所使用的内存。 //Dictionary 表示键和值的集合。Dictionary遍历输出的顺序,就是加入的顺序,这点与Hashtable不同 //SortedList类 与哈希表类似,区别在于SortedList中的Key数组排好序的 //Hashtable类 哈希表,名-值对。类似于字典(比数组更强大)。哈希表是经过优化的,访问下标的对象先散列过。如果以任意类型键值访问其中元素会快于其他集合。 GetHashCode()方法返回一个int型数据,使用这个键的值生成该int型数据。哈希表获取这个值最后返回一个索引,表示带有给定散列的数据项在字典中存储的位置。 //Stack类 栈,后进先出。push方法入栈,pop方法出栈。 Queue类 队列,先进先出。enqueue方法入队列,dequeue方法出队列。 ————————————————————- //Dictionary System.Collections.DictionaryEntry dic=new System.Collections.DictionaryEntry("key1","value1"); Dictionary<int, string> fruit = new Dictionary<int, […]
View DetailsC 货币2.5.ToString("C")¥2.50 D 十进制数25.ToString("D5")00025E 科学型25000.ToString("E")2.500000E+005F 固定点25.ToString("F2")25.00G 常规2.5.ToString("G")2.5 N 数字2500000.ToString("N")2,500,000.00X 十六进制255.ToString("X")FF formatCode 是可选的格式化代码字符串。(详细内容请搜索“格式化字符串”查看) 必须用“{”和“}”将格式与其他字符分开。如果恰好在格式中也要使用大括号,可以用连续的两个大括号表示一个大括号,即: “{{”或者“}}”。常用格式举例:(1) int i=12345;this.textBox1.Text=i.ToString();//结果 12345(this指当前对象,或叫当前类的实例)this.textBox2.Text=i.ToString("d8");//结果 00012345(2) int i=123;double j=123.45;string s1=string.Format("the value is {0,7}",i);string s2=string.Format("the value is {0,73}",j);this.textBox1.Text=s1 ;//结果 the value is 123this.textBox2.Text=s2;//结果 the value is 123.450(3)double i=12345.6789;this.textBox1.Text=i.ToString("f2"); //结果 12345.68this.textBox2.Text=i.ToString("f6");//结果 12345.678900(4)double i=12345.6789;this.textBox1.Text=i.ToString("n"); //结果 12,345.68this.textBox2.Text=i.ToString(“n4”); //结果 12,345.6789(5)double i=0.126;string s=string.Format("the value is {0:p}",i);this.textBox1.Text=i.ToString("p"); //结果 12.6%this.textBox2.Text=s; //结果 the value is 12.6%(6) DateTime dt =new DateTime(2003,5,25);this.textBox1.Text=dt.ToString("yy.M.d");//结果 03.5.25this.textBox2.Text=dt.ToString(“yyyy年M月”);//结果 2003年5月Convert.ToDateTime("2005/12/22 22:22:22").ToString("yyyy/MM/dd HHss")"2005/12/22 22:22:22"(7) int i=123;double j=123.45;string s=string.Format("i:{0,-7},j:{1,7}",i,j);//-7表示左对齐,占7位this.textBox1.Text=s ;//结果i:123 ,j: 123.45 DateTime.ToString()用法详解我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34 如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢?这里将要用到DateTime.ToString的方法(String, IFormatProvider)示例:using System;using System.Globalization;String format="D";DateTime date=DataTime.Now;Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));结果输出Thursday, June 16, 2006在这里列出了参数format格式详细用法=======================格式字符 关联属性/说明 […]
View Details由于之前一阵公司一个项目提出的需求,自己也想进行这方面的尝试,我对如何使用 Flash 来做 WinForm 程序的界面产生了兴趣,于是学习了一些资料,摘要于此。 要在 WinForm 中使用 Flash,通常需要用到 Shockwave Flash Object 这个 COM 组件。 具体步骤如下: 首先添加对 COM 组件 Shockwave Flash Object 的引用,将该组件拖到窗体上之后,可以设置如下关键属性: Movie: Flash 的存放地址 EmbedMovie: 是否嵌入到程序的资源中。 接下来你可以设置其他一些属性,使得 Flash 的窗口最大化,隐藏掉其宿主程序的 C# WinForm 窗体。 在 Flash 的 ActionScript 中,可以通过 FSCommand 函数与 hosting app 通信,该函数有两个参数,分别是: command: 命令名称 parameters: 参数 例子: on(press){ fscommand("Circule", "Green"); } 在 C# 中,处理 Flash 对象的 FSCommand 事件即可。 如果该事件处理函数的 EventArgs 为 e, 则有如下对应关系: e.command -> Flash 中调用 FSCommand 时的 command 参数; e.args -> Flash 中调用 FSCommand 时的 arguments 参数。 在 C# 中往 Flash 传递数值用 SetVariable 方法: […]
View Details1、在.net中,windows服务的实现类必需继承于System.ServiceProcess.ServiceBase public partial class myService : ServiceBase { } 2、在windows服务的实现类的构造函数中进行必要的初始化工作,如设置系统标识服务的简短名称等。 public partial class myService : ServiceBase { public SqlBackupService() { ServiceName = "Myservice"; AutoLog = false; CanStop = true; } } 3、重写OnStar和OnStop函数,在OnStar里实现具体功能,OnStop中释放OnStat中创建的资源。 public partial class myService : ServiceBase { private int tickcount = 0; private System.Timers.Timer t = null; public SqlBackupService() { ServiceName = "Myservice"; AutoLog = false; CanStop = true; } protected override void OnStart(string[] args) { Console.WriteLine("Myservice start …"); //建立定时器 t = new System.Timers.Timer(10000); t.AutoReset = true; //每隔10000毫秒触发一次 t.Elapsed += new System.Timers.ElapsedEventHandler(myWork); t.Start(); […]
View Details_ _ DbType 说明 OleDbType 说明 SqlDbType 说明 Boolean 简单类型,表示 true 或 false 的布尔值。 Boolean 布尔值 (DBTYPE_BOOL)。它映射到 Boolean。 Bit Boolean。无符号数值,可以是 0、1 或 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)。 SByte 整型,表示值介于 -128 到 127 之间的有符号 8 位整数。 TinyInt 8 位带符号的整数 (DBTYPE_I1)。它映射到 SByte。 Byte 一个 8 位无符号整数,范围在 0 到 255 之间。 UnsignedTinyInt 8 位无符号整数 (DBTYPE_UI1)。它映射到 Byte。 TinyInt Byte。8 位的无符号整数。 Int16 整型,表示值介于 -32768 到 32767 之间的有符号 16 位整数。 SmallInt 16 位带符号的整数 (DBTYPE_I2)。它映射到 Int16。 SmallInt Int16。16 位的有符号整数。 Int32 整型,表示值介于 -2147483648 到 2147483647 之间的有符号 […]
View Details
1 |
<ol class="dp-c"><li class="alt"><span><span>1.通过HttpWebResponse 来获取 </span></span></li><li><span><span class="keyword">public</span><span> </span><span class="keyword">static</span><span> </span><span class="keyword">string</span><span> CheckTeamSiteUrl(</span><span class="keyword">string</span><span> url) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">string</span><span> response = </span><span class="string">""</span><span>; </span></span></li><li class="alt"><span> HttpWebResponse httpResponse = <span class="keyword">null</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span> <span class="comment">//assert: user have access to URL </span><span> </span></span></li><li><span> <span class="keyword">try</span><span> </span></span></li><li class="alt"><span> { </span></li><li><span> HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); </span></li><li class="alt"><span> httpRequest.Headers.Set(<span class="string">"Pragma"</span><span>, </span><span class="string">"no-cache"</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span> <span class="comment">// request.Headers.Set("KeepAlive", "true"); </span><span> </span></span></li><li><span> </span></li><li class="alt"><span> httpRequest.CookieContainer = <span class="keyword">new</span><span> CookieContainer(); </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span> httpRequest.Referer = url; </span></li><li><span> </span></li><li class="alt"><span> httpRequest.UserAgent = <span class="string">"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span> httpRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; </span></li><li><span> httpResponse = (HttpWebResponse)httpRequest.GetResponse(); </span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> <span class="keyword">catch</span><span> (Exception ex) </span></span></li><li><span> { </span></li><li class="alt"><span> <span class="keyword">throw</span><span> </span><span class="keyword">new</span><span> ApplicationException(</span><span class="string">"HTTP 403 Access denied, URL: "</span><span> + url, ex); </span></span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> <span class="comment">//if here, the URL is correct and the user has access </span><span> </span></span></li><li class="alt"><span> <span class="keyword">try</span><span> </span></span></li><li><span> { </span></li><li class="alt"><span> <span class="keyword">string</span><span> strEncod = httpResponse.ContentType; </span></span></li><li><span> StreamReader stream; </span></li><li class="alt"><span> <span class="keyword">if</span><span> (strEncod.ToLower().IndexOf(</span><span class="string">"utf"</span><span>) != -1) </span></span></li><li><span> { </span></li><li class="alt"><span> stream = <span class="keyword">new</span><span> StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8); </span></span></li><li><span> } </span></li><li class="alt"><span> <span class="keyword">else</span><span> </span></span></li><li><span> { </span></li><li class="alt"><span> stream = <span class="keyword">new</span><span> StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.Default); </span></span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">char</span><span>[] buff = </span><span class="keyword">new</span><span> </span><span class="keyword">char</span><span>[4000]; </span></span></li><li class="alt"><span> stream.ReadBlock(buff,0,4000); </span></li><li><span> response = <span class="keyword">new</span><span> </span><span class="keyword">string</span><span>(buff); </span></span></li><li class="alt"><span> stream.Close(); </span></li><li><span> httpResponse.Close(); </span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">catch</span><span> (Exception ex) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">throw</span><span> </span><span class="keyword">new</span><span> ApplicationException(</span><span class="string">"HTTP 404 Page not found, URL: "</span><span> + url, ex); </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">return</span><span> response; </span></span></li><li class="alt"><span> </span></li><li><span> } </span></li><li class="alt"><span> </span></li><li> </li><li><span>2.通过 WebResponse 来获取 </span></li><li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">static</span><span> </span><span class="keyword">string</span><span> getPage(String url) </span></span></li><li><span> { </span></li><li class="alt"><span> WebResponse result = <span class="keyword">null</span><span>; </span></span></li><li><span> <span class="keyword">string</span><span> resultstring = </span><span class="string">""</span><span>; </span></span></li><li class="alt"><span> <span class="keyword">try</span><span> </span></span></li><li><span> { </span></li><li class="alt"><span> WebRequest req = WebRequest.Create(url); </span></li><li><span> req.Timeout = 30000; </span></li><li class="alt"><span> result = req.GetResponse(); </span></li><li><span> Stream ReceiveStream = result.GetResponseStream(); </span></li><li class="alt"><span> </span></li><li><span> <span class="comment">//read the stream into a string </span><span> </span></span></li><li class="alt"><span> <span class="comment">//StreamReader sr = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8); </span><span> </span></span></li><li><span> <span class="keyword">string</span><span> strEncod = result.ContentType; </span></span></li><li class="alt"><span> StreamReader sr; </span></li><li><span> <span class="keyword">if</span><span> (strEncod.ToLower().IndexOf(</span><span class="string">"utf"</span><span>) != -1) </span></span></li><li class="alt"><span> { </span></li><li><span> sr = <span class="keyword">new</span><span> StreamReader(ReceiveStream, System.Text.Encoding.UTF8); </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">else</span><span> </span></span></li><li class="alt"><span> { </span></li><li><span> sr = <span class="keyword">new</span><span> StreamReader(ReceiveStream, System.Text.Encoding.Default); </span></span></li><li class="alt"><span> } </span></li><li><span> resultstring = sr.ReadToEnd(); </span></li><li class="alt"><span> js.alert(resultstring); </span></li><li><span> <span class="comment">//Console.WriteLine(resultstring); </span><span> </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">catch</span><span> </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">throw</span><span> </span><span class="keyword">new</span><span> Exception(); </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">finally</span><span> </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">if</span><span> (result != </span><span class="keyword">null</span><span>) </span></span></li><li class="alt"><span> { </span></li><li><span> result.Close(); </span></li><li class="alt"><span> } </span></li><li><span> } </span></li><li class="alt"><span> <span class="keyword">return</span><span> resultstring; </span></span></li><li><span> } </span></li><li class="alt"><span> </span></li><li> </li><li><span>3.通过WebClient来获取 </span></li><li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">string</span><span> </span><span class="keyword">get</span><span>(</span><span class="keyword">int</span><span> length) </span></span></li><li><span> { </span></li><li class="alt"><span> <span class="keyword">try</span><span> </span></span></li><li><span> { </span></li><li class="alt"><span> getEncodeing(); </span></li><li><span> WebClient wb = <span class="keyword">new</span><span> WebClient(); </span></span></li><li class="alt"><span> Stream response = wb.OpenRead(url); </span></li><li><span> StreamReader reader = <span class="keyword">new</span><span> StreamReader(response, </span><span class="keyword">this</span><span>.encoding, </span><span class="keyword">true</span><span>, 256000); </span></span></li><li class="alt"><span> <span class="keyword">char</span><span>[] a = </span><span class="keyword">new</span><span> </span><span class="keyword">char</span><span>[length]; </span></span></li><li><span> <span class="keyword">int</span><span> i = reader.Read(a,0,length); </span></span></li><li class="alt"><span> reader.Close(); </span></li><li><span> <span class="keyword">return</span><span> </span><span class="keyword">new</span><span> </span><span class="keyword">string</span><span>(a); </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">catch</span><span> (Exception e) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">return</span><span> e.Message; </span></span></li><li class="alt"><span> <span class="comment">//return null; </span><span> </span></span></li><li><span> } </span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">private</span><span> </span><span class="keyword">void</span><span> getEncodeing() </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">switch</span><span> (</span><span class="keyword">this</span><span>.encode) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">case</span><span> </span><span class="string">"UTF-8"</span><span>: encoding = Encoding.UTF8; </span><span class="keyword">break</span><span>; </span></span></li><li class="alt"><span> <span class="keyword">case</span><span> </span><span class="string">"GB2312"</span><span>: encoding = Encoding.GetEncoding(</span><span class="string">"GB2312"</span><span>); </span><span class="keyword">break</span><span>; </span></span></li><li><span> <span class="keyword">case</span><span> </span><span class="string">"ASCII"</span><span>: encoding = Encoding.ASCII; </span><span class="keyword">break</span><span>; </span></span></li><li class="alt"><span> <span class="keyword">default</span><span>: encoding = Encoding.GetEncoding(encode); </span><span class="keyword">break</span><span>; </span></span></li><li><span> } </span></li><li class="alt"><span> } </span></li></ol> |
FROM http://blog.sina.com.cn/s/blog_758087190100rfri.html
View Details<add key="MySqlString" value="server=localhost;port=3306;user id=userid;password=123456;database=dbname;CharSet=utf8;Allow Zero Datetime=true"/>
View Detailspublic string Hello{ Response.Write("test"); Response.End9() } 客户端:2 1 using System; 2 using System.Net; 3 using System.Net.Sockets; 4 using System.Text; 5 6 public class SynchronousSocketClient { 7 8 public static void StartClient() { 9 // Data buffer for incoming data. 10 byte[] bytes = new byte[1024]; 11 12 // Connect to a remote device. 13 try { 14 // Establish the remote endpoint for the socket. 15 // This example uses port 11000 on the local computer. 16 IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()) 17 IPAddress ipAddress = ipHostInfo.AddressList[0]; 18 IPEndPoint remoteEP = […]
View Details/// <summary>/// 十进制转换为二进制/// </summary>/// <param name="x"></param>/// <returns></returns> public static string DecToBin(string x){string z = null;int X = Convert.ToInt32(x);int i = 0;long a, b = 0;while (X > 0){a = X%2;X = X/2;b = b + a*Pow(10, i);i++;}z = Convert.ToString(b);return z;} /// <summary>/// 16进制转ASCII码/// </summary>/// <param name="hexString"></param>/// <returns></returns> public static string HexToAscii(string hexString){StringBuilder sb = new StringBuilder();for (int i = 0; i <= hexString.Length – 2; i += 2){sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2),System.Globalization.NumberStyles.HexNumber))));}return sb.ToString();} /// <summary>/// 十进制转换为八进制/// </summary>/// <param name="x"></param>/// <returns></returns> public static string DecToOtc(string x){string z = null;int X = Convert.ToInt32(x);int […]
View Details