count pages for all docs in a folder

$word = New-Object -ComObject word.application $word.visible = $false $pages = 0 try { Get-ChildItem -path “.” | ? {$ -match “.*\.docx{0,1}$”} | foreach-object { write-host $ # fullName, confirmConversion, readOnly, addToRecent, passwordDocument $doc = $$_.fullname, $false, $true, $false, “”) $window = $doc.ActiveWindow; $panes = $window.Panes; $pane = $Panes.item(1) $pages += $pane.pages.count $doc.close() write-host $pages } […]

Schedule a background task in ASP.Net

private static CacheItemRemovedCallback OnCacheRemove = null; protected void Application_Start(object sender, EventArgs e) { AddTask(“DoStuff”, 60); } private void AddTask(string name, int seconds) { OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved); HttpRuntime.Cache.Insert(name, seconds, null, DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnCacheRemove); } public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r) { // do stuff here if it matches our taskname, like WebRequest […]

How to create / consume a .Net web service

[WebService(Namespace = “http://server”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class myservice : WebService { [WebMethod] public string someq(string var1, string var2) { return var1+var2; } <?php $wsdl = “http://server/service.asmx?wsdl”; $client = new SoapClient($wsdl); var_dump($client->someq(array(‘var1’=>”val1″, ‘var2’=>”val2″))); ?>

How to read a .ini file in .Net

There is no ready-made class, so you’ll have to call the Windows API [DllImport(“KERNEL32.DLL”, EntryPoint = “GetPrivateProfileStringW”, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static extern int GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, string lpReturnString, int nSize, string lpFilename); [DllImport(“KERNEL32.DLL”, EntryPoint = “WritePrivateProfileStringW”, SetLastError = true, CharSet = […]

How to connect to a MS SQL database using ASP.Net 3.5?

In web.config: <configuration> … <connectionStrings> <add name=”defaultconn” connectionString=”Data; Initial Catalog=thedatabase; Persist Security Info=True; User ID=theuser; Password=thepass” providerName=”.NET Framework Data Provider for SQL Server”/> </connectionStrings> … </configuration> In App_Code: using System.Data.SqlClient; namespace whatever { public static DataTable GetTable(string connstr, string commstr, params object[] parameters) { if (commstr == null) return null; if (connstr == null) […]

How to generate Excel from SQL data with Unicode characters

private void ExportToExcel(string strFileName, DataGrid dg) { Response.ClearContent(); Response.ContentType = “application/excel”; Response.AddHeader(“content-disposition”, “attachment; filename=” + strFileName); Response.Charset = “”; Response.ContentEncoding = System.Text.Encoding.Unicode; Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble()); this.EnableViewState = false; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); dg.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }

How to connect to a MS SQL database using ASP.Net 1.1?

1. In web.config: <configuration> … <appSettings> … <add key=”connStr” value=”server=server_name_or_ipaddress; Initial Catalog=database_name; User Id=username; Password=password;” /> … </appSettings> … </configuration> 2. In your .aspx file: <asp:Repeater ID=”rep1″ runat=”server”> <HeaderTemplate><table border=”1″></HeaderTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, “col1”) %></td> <td><%# DataBinder.Eval(Container.DataItem, “col2”) %></td> </tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater> 3. In your .aspx.cs file: using System.Data; using System.Data.SqlClient; protected Repeater […]

Bad Behavior has blocked 78 access attempts in the last 7 days.