« 1 »

[置顶] Silverlight 2.0正式版下周发布

[置顶] Silverlight 2 Beta2新功能体验

[置顶] Expression Blend 2.5 June Preview

[置顶] Microsoft Silverlight Tools Beta 2 for Visual Studio 2008

[置顶] Silverlight:Silverlight QQ群 欢迎大家

[置顶] 关于Silverlight里中文字无法显示的解決方案[整理]

[置顶] ScottGu的Silverlight2教程配套代码

[置顶] Silverlight 2.0 beta 1 及相关开发工具可以下载了!

Tags:  C#  

  最近因工作需要参与了一个.Net小 项目,语言使用C#,虽然这语言很多地方来源于Java,然而搞Java久了来搞C#还真有一点不习惯,其中一个最不习惯的是C#中的属性首字母大小。比如:...

阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:

C# 反射的用法

[ 2008年4月16日 ]
Tags:  C#  C# 反射  

在网上查找了不少的资料,可以说大同小异,概念性的东西网上一搜一堆,今天把反射的东西整理了一下,供大家使用,我保证我这里是最全面的东西,当然也是基础的东西,在学好了这一切的基础上,大家可以学习反射的具体插件等应用,老鸟就不用看了.首先我们建立一个类库,将它生成为...

阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:
Tags:  C#  扫描MAC地址  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServices;
namespace NetMAC
{
    public partial class Form1 : Form
    {
        [DllImport("iphlpapi.dll")]
        private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref  Int32 length);
        [DllImport("ws2_32.dll")]
        private static extern Int32 inet_addr(string ip);
        private delegate void SetTextCallback(string MAC, string ip, string name);
        private delegate void AddProess();
        private string Macstring = null;
        private string Fip = null ;
        private int ipNum;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            Macstring = null;
            Fip = null;
            Netprogress.Value = 0;
            try
            {
                IPAddress ip1 = IPAddress.Parse(textBox1.Text);
                IPAddress ip2 = IPAddress.Parse(textBox2.Text);
            }
          catch(Exception ei)
            {
                MessageBox.Show("扫描的IP地址有误!","NetMac");
                return;
            }
            FormatIP(textBox1.Text);
            FormatIP(textBox2.Text);
            if(Convert.ToInt32(textBox2.Text.Substring(ipNum,textBox2.Text.Length-ipNum))
                - Convert.ToInt32(textBox1.Text.Substring(ipNum,textBox1.Text.Length-ipNum)) < 0)
            {
                return ;
            }
            button1.Enabled = false;
            ProessScan(Convert.ToInt32(textBox1.Text.Substring(ipNum,textBox1.Text.Length-ipNum))
              ,Convert.ToInt32(textBox2.Text.Substring(ipNum,textBox2.Text.Length-ipNum)));
        }
        private void FormatIP(string IPaddress)  //检查IP网段
        {
            for (int i = 1; i < IPaddress.Length; i++)
            {
                if (Convert.ToChar(IPaddress.Substring(i - 1, 1)) == '.')
                {
                    ipNum = i;
                }
            }
            if (Fip != null)
            {
                if (Fip != IPaddress.Remove(ipNum))
                {
                    MessageBox.Show("扫描的网段不一致!", "NetMac");
                    return;
                }
            }
            else
            {
                Fip = IPaddress.Remove(ipNum);
            }

        }
        private void ProessScan(int startip, int ProessNum)
        {            
                Netprogress.Maximum = ProessNum - startip + 1;
            for (int i = startip; i <= ProessNum; i++)
            {
                BackgroundWorker Bgw = new BackgroundWorker();
              Bgw.DoWork += new DoWorkEventHandler(Bgw_DoWork);
              Bgw.RunWorkerAsync(Fip + i.ToString());
            }
          
        }
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            ScanMAC(e.Argument.ToString());
            ScanHostName(e.Argument.ToString());
            AddProess1();
        }
        private void AddProess1()
        {
            if (Netprogress.InvokeRequired)
            {
                Netprogress.Invoke(new AddProess(AddProess1));
            }
            else
            {
                Netprogress.Value = Netprogress.Value + 1;
            }
            if (Netprogress.Value == Netprogress.Maximum)
            {
                button1.Enabled = true;
            }
        }

        private void ScanMAC(string destIP)  //扫描MAC地址
        {
            try
            {
                IPHostEntry myip =Dns.GetHostByName(Dns.GetHostName());
                IPAddress MyAddress = new IPAddress(myip.AddressList[0].Address);
                Int32 ldest = inet_addr(destIP);
                Int32 lhost = inet_addr(MyAddress.ToString());
                Int64 mac = new Int64();
                Int32 len = 6;
                int ii = SendARP(ldest, lhost, ref  mac, ref  len);
                for (int i = 10; i >= 0; i = i - 2)
                {
                    Macstring = Macstring + mac.ToString("X4").Substring(i, 2) + "-";
                }
            }
            catch (Exception em)
            {
            }

        }
        private void ScanHostName(string hostIP) //扫描主机名字
        {
            try
            {
                IPHostEntry IPEntry = Dns.GetHostByAddress(hostIP);
                ListMac(Macstring.Remove(17), hostIP, IPEntry.HostName);
                Macstring = null;
            }
            catch (Exception eh)
            {
                
            }
        }
        private void ListMac(string MAC, string ip, string name)  //添加到列表
        {
            if (listView1.InvokeRequired)
            {
                listView1.Invoke(new SetTextCallback(ListMac), new object[] { MAC, ip, name });
            }
            else
            {
                ListViewItem li = new ListViewItem();
                li.SubItems[0].Text = MAC;
                li.SubItems.Add(ip);
                li.SubItems.Add(name);
                listView1.Items.Add(li);
            }
        }
    }
}
 

代码下载:1203832207_91200ef3.rar

...
阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:

下面的代码实现修改显示器分辨率和刷新频率的功能: ...

阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:
Tags:  检测URL是否存在  

本文用3种方法检测远程URL是否存在。

private void Page_Load(object sender, System.EventArgs e)
{

 string url1 = "http://dotnet.aspx.cc/";
 string url2 = "http://dotnet.aspx.cc/Images/logo.gif";
 Response.Write("<li>方法1:");
 Response.Write(url1 + " 存在:" + UrlExistsUsingHttpWebRequest(url1).ToString());
 Response.Write("<li>方法2:");
 Response.Write(url1 + " 存在:" + UrlExistsUsingSockets(url1).ToString());   
 Response.Write("<li>方法3:");
 Response.Write(url1 + " 存在:" + UrlExistsUsingXmlHttp(url1).ToString());

 Response.Write("<li>方法1:");
 Response.Write(url2 + " 存在:" + UrlExistsUsingHttpWebRequest(url2).ToString());
 Response.Write("<li>方法3:");
 Response.Write(url2 + " 存在:" + UrlExistsUsingXmlHttp(url2).ToString());
}
private bool UrlExistsUsingHttpWebRequest(string url)
{
 try
 {
  System.Net.HttpWebRequest myRequest =(System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
  myRequest.Method = "HEAD";
  myRequest.Timeout = 100;
  System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)myRequest.GetResponse();
  return (res.StatusCode == System.Net.HttpStatusCode.OK);
 }
 catch(System.Net.WebException we)
 {
  System.Diagnostics.Trace.Write(we.Message);
  return false;
 }
}
private bool UrlExistsUsingXmlHttp(string url)
{
 //注意:此方法需要引用Msxml2.dll
 MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
 _xmlhttp.open("HEAD",url,false,null,null);
 _xmlhttp.send("");
 return (_xmlhttp.status == 200 );
}

private bool UrlExistsUsingSockets(string url)
{
 if(url.StartsWith("http://")) url = url.Remove(0,"http://".Length);
 try
 {
  System.Net.IPHostEntry ipHost = System.Net.Dns.Resolve(url);
  return true;
 }
 catch (System.Net.Sockets.SocketException se)
 {
  System.Diagnostics.Trace.Write(se.Message);
  return false;
 }
}

...
阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:

下面的代码实现遍历 IIS 6应用程序池的一个方法:

System.DirectoryServices.DirectoryEntry appPoolRoot = new System.DirectoryServices.DirectoryEntry(@"IIS://localhost/W3SVC/AppPools");
//得到默认应用程序池的方法可以直接使用 IIS://localhost/W3SVC/AppPools/DefaultAppPool
System.Collections.IEnumerator AppPoolEnumer = appPoolRoot.Children.GetEnumerator();
while (AppPoolEnumer.MoveNext())
{
  System.DirectoryServices.DirectoryEntry EntryPool = (System.DirectoryServices.DirectoryEntry)AppPoolEnumer.Current;
  System.DirectoryServices.PropertyCollection properties = EntryPool.Properties;
  System.Collections.IDictionaryEnumerator propertiesEnumer = properties.GetEnumerator();
  textBox1.Text += "应用程序池名称 = " + EntryPool.Name + System.Environment.NewLine + "____________________________________________" + System.Environment.NewLine;
  while (propertiesEnumer.MoveNext())
  {
    System.DirectoryServices.PropertyValueCollection propertyvalue = (System.DirectoryServices.PropertyValueCollection)propertiesEnumer.Value;
    if (propertyvalue.Count > 1)
    {
      for (int j = 0; j < propertyvalue.Count; j++)
      {
        textBox1.Text += "Name=" + propertiesEnumer.Key.ToString() + "  Value= " + propertyvalue[j] + "--";
      }
    }
    else
    {
      textBox1.Text += "Name=" + propertiesEnumer.Key.ToString() + "  Value= " + propertyvalue[0] + System.Environment.NewLine;
    }
  }

...
阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:

IIS 6.0以后使用MetaBase.xml存储IIS信息,因此,可以直接修改这个文件即可。

代码如下: 很显然,这种方法比较复杂,不直观,而且需要停止IIS,影响现有网站。

 

/// <summary>
/// 本方法创建一个站点(当然,创建虚拟目录也完全没有任何问题,做法类似),并设置IIS中ASP.NET版本为2.0
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
    
//站点名称和物理路径
    String webSiteName = "mengxianhui";
    String pathToRoot 
= @"c:\mengxianhui";
    DirectoryEntry root 
= new DirectoryEntry("IIS://localhost/W3SVC");// Find unused ID value for new web site
    int siteID = 1;
    
//得到现有的站点标识
    foreach (DirectoryEntry entry in root.Children)
    {
        
if (entry.SchemaClassName == "IIsWebServer")
        {                    
            
int ID = Convert.ToInt32(entry.Name);

            
if (ID >= siteID)
            {
                siteID 
= ID + 1;
            }
       }
    }

    
//利用配置文件的做法创建站点,需要先停止原来的服务,以便能够顺利写入数据
    label1.Text = "正在停止服务……";
    Application.DoEvents();
    System.ServiceProcess.ServiceController mobServiceController3 
= new System.ServiceProcess.ServiceController("IISAdmin");
    
foreach (System.ServiceProcess.ServiceController dependentService in mobServiceController3.DependentServices)
    {
        
switch (dependentService.Status)
        {
            
case ServiceControllerStatus.Stopped:
                
break;

            
case ServiceControllerStatus.StopPending:
                dependentService.WaitForStatus(ServiceControllerStatus.Stopped);
                
break;

            
default:
                dependentService.Stop();
                dependentService.WaitForStatus(ServiceControllerStatus.Stopped);
                
break;
        }

    }
    
if (mobServiceController3.Status != ServiceControllerStatus.Stopped)
    {
        mobServiceController3.Stop();
        mobServiceController3.WaitForStatus(ServiceControllerStatus.Stopped);
    }
    
//确保服务完全停止
    label1.Text = "停止服务完成!";
    Application.DoEvents();
    String ConfigPath 
= System.Environment.SystemDirectory + @"\inetsrv\MetaBase.xml";
    System.Xml.XmlDocument doc 
= new System.Xml.XmlDocument();
    doc.Load(ConfigPath);

    System.Xml.XmlNamespaceManager xnm 
= new System.Xml.XmlNamespaceManager(doc.NameTable);
    xnm.AddNamespace(
"mxh""urn:microsoft-catalog:XML_Metabase_V64_0");

    
//得到最大的网站的标识,要在其后面加入节点
    string SiteLocation = "/LM/W3SVC/" + (siteID - 1);
    System.Xml.XmlNode LastWebServer 
= doc.SelectSingleNode("/mxh:configuration/mxh:MBProperty/mxh:IIsWebVirtualDir[@Location='" + SiteLocation + "/root']", xnm);
    
if (LastWebServer == null)
    {
        MessageBox.Show(
"没有现有的 Web 服务器。");
        doc 
= null;
        
return;
    }

    
//找到AdminACL设置,每次都是变化的 -_-!
    System.Xml.XmlNode LastWebServerFilter = doc.SelectSingleNode("/mxh:configuration/mxh:MBProperty/mxh:IIsFilters[@Location='" + SiteLocation + "/filters']/@AdminACL", xnm);
    
if (LastWebServer == null)
    {
        MessageBox.Show(
"没有现有的 Web 服务器 filters。");
        doc 
= null;
        
return;
    }

    String LastWebServerFilterAdminAcl 
= LastWebServerFilter.Value;
    
    
//创建新站点
    label1.Text = "创建新站点……";
    Application.DoEvents();
    String NewSiteID 
= "/LM/W3SVC/" + siteID.ToString();
    System.Xml.XmlNode NewWebServer 
= doc.CreateNode(System.Xml.XmlNodeType.Element, """IIsWebServer""urn:microsoft-catalog:XML_Metabase_V64_0");
    System.Xml.XmlAttribute NewWebServerLocation 
= doc.CreateAttribute("Location");
    NewWebServerLocation.Value 
= NewSiteID;
    NewWebServer.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AuthFlags");
    NewWebServerLocation.Value 
= "0";
    NewWebServer.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("ServerAutoStart");
    NewWebServerLocation.Value 
= "TRUE";
    NewWebServer.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("ServerBindings");
    NewWebServerLocation.Value 
= ":802:";
    NewWebServer.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("ServerComment");
    NewWebServerLocation.Value 
= webSiteName;
    NewWebServer.Attributes.Append(NewWebServerLocation);
    LastWebServer.ParentNode.InsertAfter(NewWebServer, LastWebServer);

    System.Xml.XmlNode NewWebServerFilter 
= doc.CreateNode(System.Xml.XmlNodeType.Element, """IIsFilters""urn:microsoft-catalog:XML_Metabase_V64_0");
    NewWebServerLocation 
= doc.CreateAttribute("Location");
    NewWebServerLocation.Value 
= NewSiteID + "/filters";
    NewWebServerFilter.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AdminACL");
    NewWebServerLocation.Value 
= LastWebServerFilterAdminAcl;
    NewWebServerFilter.Attributes.Append(NewWebServerLocation);

    NewWebServer.ParentNode.InsertAfter(NewWebServerFilter, NewWebServer);            

    System.Xml.XmlNode IIsWebVirtualDir 
= doc.CreateNode(System.Xml.XmlNodeType.Element, """IIsWebVirtualDir""urn:microsoft-catalog:XML_Metabase_V64_0");
    NewWebServerLocation 
= doc.CreateAttribute("Location");
    NewWebServerLocation.Value 
= NewSiteID + "/root";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AccessFlags");
    NewWebServerLocation.Value 
= "AccessRead | AccessScript";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AppFriendlyName");
    NewWebServerLocation.Value 
= "默认应用程序";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AppIsolated");
    NewWebServerLocation.Value 
= "2";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AppRoot");
    NewWebServerLocation.Value 
= NewSiteID + "/Root";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("AuthFlags");
    NewWebServerLocation.Value 
= "AuthAnonymous | AuthNTLM";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    
//关于权限,可以任意组合
    NewWebServerLocation = doc.CreateAttribute("DirBrowseFlags");
    NewWebServerLocation.Value 
= "DirBrowseShowDate | DirBrowseShowTime | DirBrowseShowSize | DirBrowseShowExtension | DirBrowseShowLongDate | EnableDefaultDoc";
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerLocation 
= doc.CreateAttribute("Path");
    NewWebServerLocation.Value 
= pathToRoot;
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    
//为安全起见,下面的系统文件夹需要使用程序的方法获取,如System.Environment.SystemDirectory,和System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
    
//这里为了简单期间,直接写入
    string ScriptMaps = @".asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
                .cer,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
                .cdx,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
                .asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
                .idc,C:\WINDOWS\system32\inetsrv\httpodbc.dll,5,GET,POST
                .shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
                .shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
                .stm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
                .asax,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ascx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ashx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .asmx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .aspx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .axd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .vsdisco,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .rem,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .soap,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .config,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .cs,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .csproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vbproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .webinfo,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .licx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .resx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .resources,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .xoml,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .rules,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .master,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .skin,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .compiled,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .browser,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .mdb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .jsl,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vjsproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sitemap,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .msgx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .ad,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .dd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .cd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .adprototype,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .lddprototype,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sdm,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sdmDocument,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .svc,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .mdf,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldf,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .java,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .exclude,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .refresh,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
";

    NewWebServerLocation 
= doc.CreateAttribute("ScriptMaps");
    NewWebServerLocation.Value 
= ScriptMaps;
    IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

    NewWebServerFilter.ParentNode.InsertAfter(IIsWebVirtualDir, NewWebServerFilter);
    doc.Save(ConfigPath);
    doc 
= null;

    label1.Text 
= "创建站点完成!";
    mobServiceController3 
= null;
    mobServiceController3 
= new System.ServiceProcess.ServiceController("w3svc");
    mobServiceController3.Start();
    mobServiceController3.WaitForStatus(ServiceControllerStatus.Running);
    mobServiceController3 
= null;
    label1.Text 
= "恭喜你,全部工作完成!";
    MessageBox.Show(
"恭喜你,全部工作完成!");
}


 

...
阅读全文 | 分类:C# WinForm | 评论:1 | 引用:0 | 浏览:
Tags:  .NET-3.5 Scott-Guthrie  

Scott Guthrie最近为使用.NET 3.5开发Windows客户端应用程序的开发人员所希望的改进进行了大致的描述。这些改变会在接下来的几个月里发布。 
 

这个路线图包括以下几个方面:

为客户端应用程序改进了.NET框架安装的体验

需要一并安装.NET框架可能是发布.NET客户端应用程序的最大困难之一了。微软已经承诺将简化这一过程:

Windows Form和WPF客户端应用程序能够使用这个安装框架,独立地将.NET框架安装到机器上。这个独立安装工具能够自动下载.NET 3.5客户端应用程序所需的.NET框架包。举个例子,如果一个用户已经在机器上安装了.NET 2.0,那么安装程序就能智能地识别,并自动下载.NET 2.0到3.5的升级包(而不会重新下载.NET 2.0中已经有的组件)。这个做法能够有效地降低客户端安装程序的负载大小,并提升安装体验。

我们也会为基于MSI和ClickOnce安装方案提出改进,以得到一个更完整的应用程序安装体验,并且支持一个更加友好的发布体验。
 

该安装框架可以与第三方的安装框架集成,例如InstallShield。这使最终用户能够更快地安装.NET框架。

改进了运行.NET客户端应用程序所需工作集大小和启动时间

如果没有运行使用相同版本.NET框架的其他应用程序,那么打开一个.NET应用程序所花的时间会比在框架已经加载的前提下启动第二个应用程序的时间要相对长一些。
 

我们经常被问及如何能够使.NET应用程序在“冷启动”时快一些。“冷启动”发生于一台机器上没有其他.NET客户端应用程序正在运行(或最近没有运行过)的时候,这时启动一个.NET应用程序需要操作系统从硬盘上加载许多数据页(代码,静态数据,注册表等)。如果您正在加载一个庞大的.NET客户端应用程序或类库,或者硬盘速度很慢,那么这种应用程序的“冷启动”会占用较多的时间。
今年夏天,我们会发布一个CLR的更新来进行一些非常有效的内部优化,例如我们会优化我们的数据结构来减少磁盘IO消耗,并且改进了加载和运行程序时的内存布局。作为改进所带来的好处之一,这些做法能够大大改进.NET 2.0、3.0和3.5应用程序的工作集与冷启动的性能,显著提高基于.NET的客户端应用程序的用户体验。

取决于应用程序的规模,我们期望.NET应用程序的冷启动速度能够提高25-40%。这些改进会自动生效,无需改变应用程序的任何代码,也不用重新编译。
 

WPF性能改进

这可能是开发人员最期望的更新之一了。除非运行在一台非常快速的系统上,WPF的性能看上去的确有些低。目前团队正在对一些常用组件进行更新,以帮助开发人员改进这个问题:
 

今年夏天我们计划发布一个WPF的更新,此次更新包括一系列对于文字、图像、媒体和数据栈的性能优化。这些内容包括:

- 移动DropShadow和位图模糊效果在目前是由软件进行呈现的,今后将会使用硬件加速(这样可以提高数倍性能)。这些效果的API与目前相比会保持不变(这意味着您无需改变任何代码或重新编译即可获得这些优化)。

- 对于文本渲染场景,尤其在使用Visual和DrawingBrush场景时,性能会得到充分的改善。这些API同样会保持不变(这意味着您无需改变任何代码或重新编译即可获得这些优化)。

- 媒体和视频的性能同样会快的多(同样无需改变任何代码或重新编译即可获得这些优化)。

- 我们的更新会包含一个新的WriteableBitmap API,能够根据一个软件的表面实时地更新位图。我们同样添加了一些强大的API,使您可以构建更为丰富的图像场景。

- 我们的更新还包括了新的数据扩展性改进,它们能够用于数据编辑场景。这些改进包括容器回收和数据可视化的支持,这使得开发一个数据表现效果丰富的控件变得更加容易。

WPF控件改进

我经常向开发人员谈论使用WPF的话题,一个比较普遍的抱怨就是可以使用的控件数量。微软同样会对此进行改进:
 

今年晚些时候,我们同样计划发布一些WPF的新控件。我们正在开发的有DataGrid、Ribbon以及Calendar/DatePicker等控件。
 

对于那些期待额外控件的人来说,这些新的控件对于促进使用WPF大有帮助。
 

Visual Studio 2008 WPF设计器改进
 

目前的WPF设计器缺乏开发人员熟悉的某些功能,最后一部分改进正是针对这点:
 

我们同样计划发布一个VS 2008的服务更新,包括一些对WPF设计器功能的增强。这些改进包括属性面板中对于控件事件标签的支持,源代码模式下的工具箱支持,以及一些经常被提及的功能改进。
 

这些升级能够帮助开发人员更方便地开发桌面应用程序,而且在大多数情况下并不需要改变代码。不过开发人员需要了解的是,这些改进只支持.NET 3.5框架和Visual Studio 2008。

...
阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:
Tags:  C# DataGridView EXCEL  
        #region 将DataGridView控件中数据导出到Excel

        
/// <summary>

        
/// 将DataGridView控件中数据导出到Excel

        
/// </summary>

        
/// <param name="gridView">DataGridView对象</param>

        
/// <param name="isShowExcle">是否显示Excel界面</param>

        
/// <returns></returns>

        public bool ExportDataGridview(DataGridView gridView,bool isShowExcle)

        {

            
if (gridView.Rows.Count == 0)

                
return false;

            
//建立Excel对象

            Excel.Application excel = new Excel.Application();

            excel.Application.Workbooks.Add(
true);

            excel.Visible 
= isShowExcle;

            
//生成字段名称

            for (int i = 0; i < gridView.ColumnCount; i++)

            {

                excel.Cells[
1, i + 1= gridView.Columns[i].HeaderText;

            }

            
//填充数据

            for (int i = 0; i < gridView.RowCount-1; i++)

            {

                
for (int j = 0; j < gridView.ColumnCount; j++)

                {

                    
if (gridView[j, i].ValueType == typeof(string))

                    {

                        excel.Cells[i 
+ 2, j + 1= "'" + gridView[j, i].Value.ToString();

                    }

                    
else

                    {

                        excel.Cells[i 
+ 2, j + 1= gridView[j, i].Value.ToString();

                    }

                }

            }

            
return true;

        }
        #endregion
阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:

C#中调用windows API函数

[ 2007年12月31日 ]

对于windows 系统API函数的调用在程序设计中有时是必不可少的,各种编程语言都规范了调用的方法和接口......

阅读全文 | 分类:C# WinForm | 评论:0 | 引用:0 | 浏览:
分页: « 1 »