Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Gathering html id's from asp.net

The basic idea here is to pull the id's from asp.net so that it can be used in a javascript environment.

   1  
   2  <input id="GetLocation" type="button" onclick="getLocation(<%=tbStreet.clientID %>.value + ' ' + <%=tbCity.clientID %>.value + ' ' + <%=tbState.clientID %>.value + ' ' + <%=tbZip.clientID %>.value,'<%=lblLocation.clientID %>');" value="Get Location" />

Using Rows.Find in ADO.NET

When using a DataTable in ADO.NET, you may want to search your table given a key. The Find method requires the index of the primary key to find the row that you're looking for. However, before you do this you must set the primary key of the Datatable. Setting the primary key in your database is not enough. To set the primary key, create a new column and then set the primary key field on the Datatable like so:

   1  
   2  
   3  // Create the DataColumn list for holding the columns of the primary keys. In this case, we are using only one primary key
   4  DataColumn[] primaryKeyColumns = new DataColumn[1];
   5  
   6  // Set the first primary key to the column 'id' in the datatable
   7  primaryKeyColumns[0] = myDataTable.Columns["id"];
   8  
   9  // Now apply the primary key to the datatable
  10  myDataTable.PrimaryKey = primaryKeyColumns;

获�Exchange未读邮件数

// description of your code here

   1  
   2  private int GetUnReadMailCount()
   3  {
   4  string url=“http://mail.felixwoo.com/exchange/â€?; //指定Exchange朊¡å™¨åœ°å?€ 
   5  System.Net.HttpWebRequest Request;
   6  System.Net.WebResponse Response;
   7  System.Net.CredentialCache MyCredentialCache;
   8  string strUserName = “wufâ€?; //指定登录的用户å??
   9  string strRootURI = url+strUserName ; //得到覮¿é—®é‚®ç®±çš„WebDAV地å?€
  10  string strPassword = “123456�; //指定该用户的密�
  11  string strDomain = “felixwoo.comâ€?; //指定域å??
  12  string strQuery ="";
  13  byte[] bytes = null;
  14  System.IO.Stream RequestStream = null;
  15  System.IO.Stream ResponseStream = null;
  16  XmlDocument ResponseXmlDoc = null;
  17  XmlNodeList HrefNodes= null;
  18  XmlNodeList SizeNodes= null;
  19  int count=0;
  20  try
  21  {
  22    // 用SQL查询WebDAV返回结果中的unreadcount节点.
  23    strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >"
  24     + "<D:sql>SELECT \"DAV:displayname\",\"urn:schemas:httpmail:unreadcount\" FROM \"" + strRootURI + "\""
  25     + "</D:sql></D:searchrequest>";
  26  
  27    // 创建新的CredentialCache对象,构建身份凭æ
  28    MyCredentialCache = new System.Net.CredentialCache();
  29    MyCredentialCache.Add( new System.Uri(strRootURI),
  30     "NTLM",
  31     new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
  32     );
  33  
  34    // Create the HttpWebRequest object.
  35    Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
  36  
  37    // 指定HttpWebRequest的身份凭æï¼Œæ­¤å¤„为关键所在。如果使用之å‰?
  38    // 创建的MyCredentialCacheï¼Œåˆ™è¿™ä¸ªèº«ä»½å‡­ææ˜¯å以从Web朊¡å™¨ä¼ é€’
  39    // 到Exchange朊¡å™¨çš„,但是这样带æçš„问题也很明显,就是七½å¤Ÿè‡ª
  40    // 动获å?–当剙»å½•到域的用户的身份。åä¾¿å·²ç»ˆŠŸç™»å½•åˆ°åŸŸï¼Œé‚£ä¹Ÿå
  41    // 能通过form冬¡è¾“入用户å??密砀‚因此,我在这里用的是
  42    // Request.Credentials = CredentialCache.DefaultCredentials,
  43    // 这样便å以获得当剔¨æˆ·çš„凭æï¼Œä½†æ˜¯è¿™æ ·å¸¦æçš„问题便是上éæ??到的
  44    // èº«ä»½å‡­ææ— æ³•传递的问题,解决方法请关注下篇文章。
  45    Request.Credentials = MyCredentialCache;
  46  
  47    // 指定WebDAV的SEARCH方法
  48    Request.Method = "SEARCH";
  49  
  50    // Encode the body using UTF-8.
  51    bytes = Encoding.UTF8.GetBytes((string)strQuery);
  52  
  53    // Set the content header length. This must be
  54    // done before writing data to the request stream.
  55    Request.ContentLength = bytes.Length;
  56  
  57    // Get a reference to the request stream.
  58    RequestStream = Request.GetRequestStream();
  59  
  60    // Write the SQL query to the request stream.
  61    RequestStream.Write(bytes, 0, bytes.Length);
  62  
  63    // Close the Stream object to release the connection
  64    // for further use.
  65    RequestStream.Close();
  66  
  67    // Set the content type header.
  68    Request.ContentType = "text/xml";
  69  
  70    // Send the SEARCH method request and get the
  71    // response from the server.
  72    Response = (HttpWebResponse)Request.GetResponse();
  73  
  74    // Get the XML response stream.
  75    ResponseStream = Response.GetResponseStream();
  76  
  77    // 创建XmlDocument对象,并获�收件箱的unreadcount节点的值
  78    ResponseXmlDoc = new XmlDocument();
  79    ResponseXmlDoc.Load(ResponseStream);
  80    HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");
  81    SizeNodes = ResponseXmlDoc.GetElementsByTagName("d:unreadcount");
  82    for(int i=0;i<HrefNodes.Count;i++)
  83    {
  84     if(HrefNodes[i].InnerText=="æ”¶ä»¶ç®±")
  85      count=int.Parse(SizeNodes[i].InnerText);
  86    }
  87    ResponseStream.Close();
  88    Response.Close();
  89  }
  90  catch(Exception)
  91  {
  92    // Catch any exceptions. Any error codes from the SEARCH
  93    // method request on the server will be caught here, also.
  94    return -1;
  95  }
  96  return count;
  97  } 

Create Graphiz image from Dot file using DotNet

This is from http://vv.cs.byu.edu/cs312-003/archives/2005/01/graph_visualiza.html. Go there for more info.
   1  
   2   private void button2_Click(object sender, System.EventArgs e) {
   3  
   4  string strCmdLine1 = "-Tsvg -o c:\\tmp\\foo.xml c:\\tmp\\ER.dot";
   5  string strCmdLine2 = "-Tsvg -o c:\\tmp\\foo.xml c:\\tmp\\Heawood.dot";
   6  System.Diagnostics.Process p = new System.Diagnostics.Process();
   7  
   8  p.StartInfo.FileName = "\"C:\\Program Files\\ATT\\Graphviz\\bin\\dot.exe\"";
   9  p.StartInfo.CreateNoWindow = true;
  10  p.StartInfo.UseShellExecute = false;
  11  if (graphIndex == 0)
  12  p.StartInfo.Arguments = strCmdLine2;
  13  else
  14  p.StartInfo.Arguments = strCmdLine1;
  15  
  16  p.Start();
  17  p.WaitForExit();
  18  
  19  axSVGCtl1.reload();
  20  graphIndex = (graphIndex + 1) % 2;
  21  }
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS