Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Copy/Delete/Permission directory using System; using System.IO; using System.Security.AccessControl; namespace Bruce.Lib {     public class DirHelper     {         /// <...
Stats
Social Data Service

http://YOUR_SERVER_URL/PATH_TO_SITE_CONTAINING_LIST/_vti_bin/socialdataservice.asmx

C# 4.0's New Features
Named and Optional Parameters
  1. public class Person
  2. {
  3. public Person(string name, string gender = "Unknow", int age = 18) { }
  4. }
  5.  
  6. var p1 = new Person("Bruce"); // only primary parameter
  7. var p2 = new Person("Bruce", "Male"); // one optional parameter
  8. var p3 = new Person("Bruce", "Male", 20); // all parameters
  9. var p4 = new Person("Bruce", age: 20); // specified optional parameters

Dynamic Support
  1. dynamic foo = 123;
  2. foo = "foo";
  3.  
  4. dynamic p = new System.Dynamic.ExpandoObject();
  5. p.age = 20;
  6. p.name = "bruce";
Capitalize First Letters Of Words
  1. string str = "EXTERNAL";
  2. str = new string(str.Select((c, index) => index == 0 ? char.ToUpper(c) : char.ToLower(c)).ToArray());
  3. Console.WriteLine(str);
  4. // output: External
Get user info by account
  1. SPUser user = SPContext.Current.Web.EnsureUser("domain\account");
Export list schema from sharepoint

http://YOUR_SERVER_URL/PATH_TO_SITE_CONTAINING_LIST/_vti_bin/owssvr.dll?Cmd=ExportList&List={YOUR_LIST_GUID}

Paging on SQL Server 2012
SQL Server 2008-   Paging by row_number() function:
  1. declare @JobID varchar(max);
  2. declare @JobName nvarchar(max);
  3. declare @CompanyName nvarchar(max);
  4. declare @DataSource nvarchar(max);
  5. declare @JobCategory nvarchar(max);
  6. declare @Area nvarchar(max);
  7. declare @PageIndex int;
  8. declare @PageSize int;
  9.  
  10. set @PageIndex=1;
  11. set @PageSize=20;
  12.  
  13. select
  14.     d.*
  15. from
  16. (
  17.     select
  18.         ROW_NUMBER() over(order by JobName asc) RowIndex,  -- sortField, sortOrder
  19.         v.*
  20.     from JobDataView v
  21.     inner join
  22.     (
  23.         select distinct JobID
  24.         from JobDataSheet
  25.         where
  26.             (@JobID is null or JobID=@JobID)
  27.         and (@JobName is null or JobName like '%'+@JobName+'%')
  28.         and (@CompanyName is null or CompanyName like '%'+@CompanyName+'%')
  29.         and (@DataSource is null or DataSource=@DataSource)
  30.         and (@JobCategory is null or CategoryName=@JobCategory)
  31.         and (@Area is null or (InfoName='Area' and InfoValue like '%'+@Area+'%'))
  32.     ) s on s.JobID=v.JobID
  33. ) d
  34. where d.RowIndex > (@PageIndex-1)*@PageSize and d.RowIndex <= @PageIndex*@PageSize;
SQL Server 2012   Paging by offset|fetch:
  1. declare @JobID varchar(max);
  2. declare @JobName nvarchar(max);
  3. declare @CompanyName nvarchar(max);
  4. declare @DataSource nvarchar(max);
  5. declare @JobCategory nvarchar(max);
  6. declare @Area nvarchar(max);
  7. declare @PageIndex int;
  8. declare @PageSize int;
  9.  
  10. set @PageIndex=1;
  11. set @PageSize=20;
  12.  
  13. select
  14.     v.*
  15. from JobDataView v
  16. inner join
  17. (
  18.     select distinct JobID
  19.     from JobDataSheet
  20.     where
  21.         (@JobID is null or JobID=@JobID)
  22.     and (@JobName is null or JobName like '%'+@JobName+'%')
  23.     and (@CompanyName is null or CompanyName like '%'+@CompanyName+'%')
  24.     and (@DataSource is null or DataSource=@DataSource)
  25.     and (@JobCategory is null or CategoryName=@JobCategory)
  26.     and (@Area is null or (InfoName='Area' and InfoValue like '%'+@Area+'%'))
  27. ) s on s.JobID=v.JobID
  28. order by v.JobName asc
  29. offset (@PageIndex-1)*@PageSize rows
  30. fetch next @PageSize rows only
reference : http://msdn.microsoft.com/en-us/library/ms188385%28v=SQL.110%29.aspx
Web.config setting of mvc
  1.   <system.webServer>
  2.     <validation validateIntegratedModeConfiguration="false" /><modules runAllManagedModulesForAllRequests="true">
  3.             <remove name="ScriptModule" />
  4.             <remove name="UrlRoutingModule" />
  5.             <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  6.             <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  7.         </modules>
  8.         <handlers>
  9.             <remove name="WebServiceHandlerFactory-Integrated" />
  10.             <remove name="ScriptHandlerFactory" />
  11.             <remove name="ScriptHandlerFactoryAppServices" />
  12.             <remove name="ScriptResource" />
  13.             <remove name="MvcHttpHandler" />
  14.             <remove name="UrlRoutingHandler" />
  15.             <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  16.             <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  17.             <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  18.             <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  19.             <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  20.         </handlers>
  21.   </system.webServer>
Batch insert using SqlDataAdapter
  1. string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["JobHunter"].ConnectionString;
  2. using (SqlConnection conn = new SqlConnection(connStr))
  3. {
  4.     conn.Open();
  5.  
  6.     #region
  7.     string JobID = Guid.NewGuid().ToString();
  8.     HashSet<string> JobCategory = new HashSet<string>(new string[] { 
  9.        "Windows 8標準搭載のセキュリティ Windows Defenderとは - トレンドマイクロ",
  10.         "Windows 8対応 パスワードマネージャー Modern UI版 - トレンドマイクロ",
  11.         "Windows 8にもマルウェア対策は必須 - トレンドマイクロ",
  12.         "Windows 8にもWeb脅威対策は必須 - トレンドマイクロ",
  13.         "Windows 8でも、面倒なパスワード入力はしない。 - トレンドマイクロ",
  14.         "Windows 8 最新のセキュリティにも対応 - トレンドマイクロ",
  15.         "Windows 8 もウイルスバスタークラウドで安心! border=",
  16.         "Windows 8 のセキュリティ対策もウイルスバスター クラウド - トレンドマイクロ",
  17.         "Windows 8 Modern UI向け無料アプリ Windows ストアアプリ",
  18.         "Windows 8 Modern UI向け Windows ストアアプリ - トレンドマイクロ",
  19.         "Windows 8 Modern UI向け 3種類のWindows ストアアプリ - トレンドマイクロ"
  20.     });
  21.     #endregion
  22.  
  23.     using (System.Data.SqlClient.SqlDataAdapter adapter 
  24.         = new System.Data.SqlClient.SqlDataAdapter(@"select top 0 * from JobCategory", conn))
  25.     {
  26.         // add insert command
  27.         adapter.InsertCommand = new SqlCommand(@"insert into JobCategory values(@JobID, @CategoryName);", conn);
  28.         adapter.InsertCommand.Parameters.Add("@JobID", SqlDbType.VarChar, 50, "JobID");
  29.         adapter.InsertCommand.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 50, "CategoryName");
  30.         adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
  31.  
  32.         DataTable dt = new DataTable();
  33.         adapter.Fill(dt);
  34.  
  35.         foreach (string name in JobCategory)
  36.         {
  37.             dt.Rows.Add(JobID, name);
  38.         }
  39.  
  40.         // one-time update
  41.         adapter.UpdateBatchSize = 0;
  42.         adapter.Update(dt);
  43.     }
  44. }