目前分類:C# (17)

瀏覽方式: 標題列表 簡短摘要

增加一個event 讓 Process 在執行完畢的時候判斷用

private static  void process_Exited(object sender, EventArgs e) {
Console.WriteLine("Notepad.exe 已被關閉!!!");
}


文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

程式碼如下

string AD_RootPath = "LDAP://AD的IP或是電腦名稱/cn=Users,dc=網域,例:example,dc=網域,例:com";
DirectoryEntry entry = new DirectoryEntry(AD_RootPath, 帳號,密碼, AuthenticationTypes.Secure); 
DirectorySearcher deSearch = new DirectorySearcher(entry);
foreach (SearchResult res in deSearch.FindAll())
{
        foreach (string key in res.Properties.PropertyNames)
        {
                foreach (object val in res.Properties[key])
                {
                string v=key+"="+val;
                Response.Write(v + "<BR>");
                }
        }
Response.Write( "------------------------------------------------------------------------------------------------<BR>");
}

文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

參考:http://blog.xuite.net/yan.kee/CSharp/14844624?ref=rel

解法如下

C# 加上下面的CODE就OK了  

public override void VerifyRenderingInServerForm(Control control)
        {

文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

如何使用linq再新增後取得流水號

image

很簡單輸入這行就可以達到效果了。^^


文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

好站:http://www.flounder.com/csharp_color_table.htm

using System.Drawing;

color c=Color.FromKnownColor(KnownColor.DarkRed);

KnownColor.DarkRed<==使用系統預設顏色碼

上面網站有詳細的顏色對照。

Empty 發表在 痞客邦 留言(0) 人氣()

 

使用Regex 還有 MatchCollection, 引用命名空間using System.Text.RegularExpressions;

方法如下

 

1 MatchCollection mc;

Empty 發表在 痞客邦 留言(0) 人氣()

ChartFX 是一個很強大的圖表軟體, 特別是到了 2005 的版本之後, 運用了 DHTML 和 AJAX 的技術, 讓原先要透過安裝 ActiveX 才能達到的效果, 也可以直接在網頁上呈現, 而且互動性也像 ActiveX 一樣的好, 但是代價就是要多付出一些 server 和 client 之間資料的來回傳送!

在實際使用 ChartFX 7.0 開發 Web App 的時候,  發現了一個現象, 就是如果透過 Visual Studio 內建的 WebDev.WebServer.exe 啟動的話, ChartFX 的暫存檔會輸出到 ~/chartfx70/temp/ 底下, 可是當佈署到 IIS 之後, 它會在 WebSite 的根目錄下建立一個 /chartfx70 虛擬目錄, 這時候如果透過 ISA 將內部網站發佈出去的話, 除了要開放該 Web 應用程式的路徑之外, 就還要再多開放一個 /chartfx70 的路徑, 外部的人才可以順利的取得 chart 的內容, 雖然動作不難, 但是還要動到 ISA 的設定也是有點不方便, 所以才想找個方法讓 chartfx 的輸出路徑改變一下!

在 google 上找了很久, 其實沒有找到答案, 但是有找到一點點看起來不太像的線索, 最後還是透過 Reflector 才搞定了這個問題!!

image

Empty 發表在 痞客邦 留言(1) 人氣()

以下文章轉錄至:

程式碼命名與撰寫規範 (不定時更新)

 

Empty 發表在 痞客邦 留言(0) 人氣()

asp.net 2.0 使用 

在PostBack後網頁通常會回到最頂端的位置,下面三個方式可以讓單頁或整個Web或目錄PostBack後回到原來停留的位置.

1. Web.config

1 //在<system.web></system.web>之間增加節點
2 <pages maintainScrollPositionOnPostBack="true"></pages>

Empty 發表在 痞客邦 留言(0) 人氣()

A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode="<code></code>"). 

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set requestValidationMode="2.0" in the configuration section. After setting this value, you can then disable request validation by setting validateRequest="false" in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information, see http://go.microsoft.com/fwlink/?LinkId=153133. 

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode="<code></code>").

Empty 發表在 痞客邦 留言(0) 人氣()

好吧!這一次真的是我太嫩了!短短接觸 .NET 平台雖然不到半年,我這次認栽了!

  • TextBox 如果把 ReadOnly 屬性設定為 True,透過 JavaScript 設定的值,在 ASP.NET 2.0 是無法取到值的!

今天,就為了這小小的 Bug,不知道浪費多久的時間,殺死了多少的腦細胞!唉!只能說我還是太嫩了,寫的程式不夠多!還以為真的是七月,見到鬼了,一行一行 trace,明明眼看 TextBox 中有值,卻無法取用!幸好, Google 讓我搜尋到解答,早在 2005 的時候,就有人提出解決辦法了!Orz

解決之道:

  1. 利用 Request 來取值。
  2. 如果非要使用 textBox.Text 來取值的話,textBox. ReadOnly 記的還是設為 false 。但是在 Page_Load,加入 textBox.Attributes.Add("ReadOnly", "ReadOnly") 即可。

Empty 發表在 痞客邦 留言(0) 人氣()

在很多程式裡都有四捨五入Round的功能,但其四捨五入的結果是否真如預期?負數的四捨五入是什麼結果? 以下用JavaScript / .Net / Oracle /MS SQL /Excel  這幾種語言或工具來看看,結果都是出乎預料之外...

 
正數的四捨五入大都多什麼問題,問題在於負數,負數要怎麼四捨五入? 
 
JavaScript
文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

此程序利用 WinRAR 程序对文件进行压缩,命令行语法可参考WinRAR中文帮助。 

 

代码  
  1. /// <summary>  
  2. /// 利用 WinRAR 进行压缩  
  3. /// </summary>  
  4. /// <param name="path">将要被压缩的文件夹(绝对路径)</param>  
  5. /// <param name="rarPath">压缩后的 .rar 的存放目录(绝对路径)</param>  
  6. /// <param name="rarName">压缩文件的名称(包括后缀)</param>  
  7. /// <returns>true 或 false。压缩成功返回 true,反之,false。</returns>  
  8. public bool RAR(string path, string rarPath, string rarName)  
  9. {  
  10.     bool flag = false;  
  11.     string rarexe;       //WinRAR.exe 的完整路径  
  12.     RegistryKey regkey;  //注册表键  
  13.     Object regvalue;     //键值  
  14.     string cmd;          //WinRAR 命令参数  
  15.     ProcessStartInfo startinfo;  
  16.     Process process;  
  17.     try  
  18.     {  
  19.         regkey = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\shell\open\command");  
  20.         regvalue = regkey.GetValue("");  // 键值为 "d:\Program Files\WinRAR\WinRAR.exe" "%1"  
  21.         rarexe = regvalue.ToString();      
  22.         regkey.Close();  
  23.         rarexe = rarexe.Substring(1, rarexe.Length - 7);  // d:\Program Files\WinRAR\WinRAR.exe  
  24.         Directory.CreateDirectory(path);  
  25.         //压缩命令,相当于在要压缩的文件夹(path)上点右键 ->WinRAR->添加到压缩文件->输入压缩文件名(rarName)  
  26.         cmd = string.Format("a {0} {1} -r", rarName, path);  
  27.         startinfo = new ProcessStartInfo();  
  28.         startinfo.FileName = rarexe;  
  29.         startinfo.Arguments = cmd;                          //设置命令参数  
  30.         startinfo.WindowStyle = ProcessWindowStyle.Hidden;  //隐藏 WinRAR 窗口  
  31.         startinfo.WorkingDirectory = rarPath;  
  32.         process = new Process();  
  33.         process.StartInfo = startinfo;  
  34.         process.Start();  
  35.         process.WaitForExit(); //无限期等待进程 winrar.exe 退出  
  36.         if (process.HasExited)  
  37.         {  
  38.             flag = true;  
  39.         }  
  40.         process.Close();  
  41.     }  
  42.     catch (Exception e)  
  43.     {  
  44.         throw e;  
  45.     }  
  46.     return flag;  
  47. }  
  48. /// <summary>  
  49. /// 利用 WinRAR 进行解压缩  
  50. /// </summary>  
  51. /// <param name="path">文件解压路径(绝对)</param>  
  52. /// <param name="rarPath">将要解压缩的 .rar 文件的存放目录(绝对路径)</param>  
  53. /// <param name="rarName">将要解压缩的 .rar 文件名(包括后缀)</param>  
  54. /// <returns>true 或 false。解压缩成功返回 true,反之,false。</returns>  
  55. public bool UnRAR(string path, string rarPath, string rarName)  
  56. {  
  57.     bool flag = false;  
  58.     string rarexe;  
  59.     RegistryKey regkey;  
  60.     Object regvalue;  
  61.     string cmd;  
  62.     ProcessStartInfo startinfo;  
  63.     Process process;  
  64.     try  
  65.     {  
  66.         regkey = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\shell\open\command");  
  67.         regvalue = regkey.GetValue("");  
  68.         rarexe = regvalue.ToString();  
  69.         regkey.Close();  
  70.         rarexe = rarexe.Substring(1, rarexe.Length - 7);  
  71.         Directory.CreateDirectory(path);  
  72.         //解压缩命令,相当于在要压缩文件(rarName)上点右键 ->WinRAR->解压到当前文件夹  
  73.         cmd = string.Format("x {0} {1} -y", rarName, path);  
  74.         startinfo = new ProcessStartInfo();  
  75.         startinfo.FileName = rarexe;  
  76.         startinfo.Arguments = cmd;  
  77.         startinfo.WindowStyle = ProcessWindowStyle.Hidden;  
  78.         startinfo.WorkingDirectory = rarPath;  
  79.         process = new Process();  
  80.         process.StartInfo = startinfo;  
  81.         process.Start();  
  82.         process.WaitForExit();  
  83.         if (process.HasExited)  
  84.         {  
  85.             flag = true;  
  86.         }  
  87.         process.Close();  
  88.     }  
  89.     catch (Exception e)  
  90.     {  
  91.         throw e;  
  92.     }  
  93.     return flag;  
  94. }  

在dos或者cmd下用cd命令进入到winrar的安装目录后,输入unrar可出来以下提示: 

文章標籤

Empty 發表在 痞客邦 留言(0) 人氣()

在 .aspx.cs 可以使用 Server.MapPath() or Request.MapPath() 來取伺服器的實體路徑,不過在Class檔中是沒有這兩個玩意的

 所以就用 HttpContext.Current.Server.MapPath("/MyWeb") 來抓路徑,引號內為 IIS 資料夾位置,若只有 "/" 則取根目錄

 

參考:http://www.dotblogs.com.tw/jjwei/archive/2010/10/07/18185.aspx

Empty 發表在 痞客邦 留言(0) 人氣()

 

參考:

http://www.dotblogs.com.tw/hatelove/archive/2009/01/21/6906.aspx


Empty 發表在 痞客邦 留言(0) 人氣()

<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

<html>
    <head>
        <script runat="server">
            private void Page_Load(object sender, System.EventArgs e)
            {
                // Create a TableItemStyle object that can be
                // set as the default style for all cells
                // in the table.
                TableItemStyle tableStyle = new TableItemStyle();
                tableStyle.HorizontalAlign = HorizontalAlign.Center;
                tableStyle.VerticalAlign = VerticalAlign.Middle;
                tableStyle.Width = Unit.Pixel(100);

                // Create more rows for the table.
                for (int i = 2; i < 10; i++)
                {
                    TableRow tempRow = new TableRow();
                    for (int j = 0; j < 3; j++)
                    {
                        TableCell tempCell = new TableCell();
                        tempCell.Text = "(" + i + "," + j + ")";
                        tempRow.Cells.Add(tempCell);
                    }
                    Table1.Rows.Add(tempRow);
                }

                // Apply the TableItemStyle to all rows in the table.
                foreach (TableRow r in Table1.Rows)
                    foreach (TableCell c in r.Cells)
                        c.ApplyStyle(tableStyle);

                // Create a header for the table.
                TableHeaderCell header = new TableHeaderCell();
                header.RowSpan = 1;
                header.ColumnSpan = 3;
                header.Text = "Table of (x,y) Values";
                header.Font.Bold = true;
                header.BackColor = Color.Gray;
                header.HorizontalAlign = HorizontalAlign.Center;
                header.VerticalAlign = VerticalAlign.Middle;

                // Add the header to a new row.
                TableRow headerRow = new TableRow();
                headerRow.Cells.Add(header);

                // Add the header row to the table.
                Table1.Rows.AddAt(0, headerRow);  
            }
        </script>
    </head>

    <body>
        <form runat="server">
            <h1>TableCell Example</h1>
            <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
                <asp:TableRow>
                    <asp:TableCell Text="(0,0)"></asp:TableCell>
                    <asp:TableCell Text="(0,1)"></asp:TableCell>
                    <asp:TableCell Text="(0,2)"></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell Text="(1,0)"></asp:TableCell>
                    <asp:TableCell Text="(1,1)"></asp:TableCell>
                    <asp:TableCell Text="(1,2)"></asp:TableCell>
                </asp:TableRow>
            </asp:table>
        </form>
    </body>
</html>

參考:
http://msdn.microsoft.com/zh-tw/library/tk1zfd2e(VS.80).aspx
http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.webcontrol.borderwidth(v=VS.80).aspx

Empty 發表在 痞客邦 留言(0) 人氣()

顯示了頁面生命週期中的主要步驟。 只要 ASP.NET 請求到達 Web 伺服器並找到對其進行處理的 HTTP 處理常式後,就會執行圖仲介紹的步驟。 您可以看到,簡單的按鈕按一下操作的代碼只是整個 ASP.NET 基礎結構的一小部分。 稍後您會看到,頁面生命週期僅是 ASP.NET 運行時為了處理每個請求所執行的操作的一部分。
圖 1 ASP.NET 頁面生命週期
在執行 Button1_Click 中的代碼前,ASP.NET 運行時會創建一個 Page 類的實例,以保存請求的 URL 的預期行為。 此 Page 類按照圖 1 中的步驟處理請求,並在適當的時候使用您的事件處理常式。
在控制器類中的 Button1Clicked 方法中,您應該能夠利用在純代碼隱藏事件處理常式中使用的同一語法訪問頁面中的任何控制項。 但引用 UI 控制項(假設是 TextBox1)的成員不是 Page 類上的公共成員,您如何使控制器可以訪問它們?您可以在代碼隱藏類上實現一個自訂介面,使其包含您要在控制器中操作的 UI 控制項的公共屬性。

Empty 發表在 痞客邦 留言(0) 人氣()