snipt

Ctrl+h for KB shortcuts

C#

Get Worksheet object by name

1
2
3
using Excel = Microsoft.Office.Interop.Excel;

Excel.Worksheet worksheet = (Excel.Worksheet)Globals.ThisWorkbook.Worksheets["SheetName"];
https://snipt.net/embed/d1d482e015b9d2eafcb1828a2e40d380/
/raw/d1d482e015b9d2eafcb1828a2e40d380/
d1d482e015b9d2eafcb1828a2e40d380
csharp
C#
3
2019-07-08T00:19:09
True
False
False
/api/public/snipt/38002/
get-worksheet-object-by-name
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">using</span> <span class="nn">Excel</span> <span class="p">=</span> <span class="n">Microsoft</span><span class="p">.</span><span class="n">Office</span><span class="p">.</span><span class="n">Interop</span><span class="p">.</span><span class="n">Excel</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span> <span class="n">worksheet</span> <span class="p">=</span> <span class="p">(</span><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span><span class="p">)</span><span class="n">Globals</span><span class="p">.</span><span class="n">ThisWorkbook</span><span class="p">.</span><span class="n">Worksheets</span><span class="p">[</span><span class="s">&quot;SheetName&quot;</span><span class="p">];</span> </span></pre></div> </td></tr></table>
vsto

Batchfile

MySQL back up whole database

1
2
3
4
mysqldump -h [hostname] -u[Username] -p[Password] [DatabaseName] > /home/content/96/7858396/html/_db_backups/db_daily_backup.sql


//When replace, donot add brackets.
https://snipt.net/embed/2b178713ea21aff97e11dd6a1a89e7f6/
/raw/2b178713ea21aff97e11dd6a1a89e7f6/
2b178713ea21aff97e11dd6a1a89e7f6
bat
Batchfile
4
2019-07-14T17:19:45
True
False
False
/api/public/snipt/37737/
mysql-back-up-whole-database
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysqldump -h [hostname] -u[Username] -p[Password] [DatabaseName] <span class="p">&gt;</span> /home/content/96/7858396/html/_db_backups/db_daily_backup.sql </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>//When replace, donot add brackets. </span></pre></div> </td></tr></table>
cmd, mysql

C#

Get number of Days between two DateTime

1
2
3
DateTime d1;
DateTime d2;
double diff = (d1 - d2).TotalDays;
https://snipt.net/embed/ef8528afb70c446ac1c97c8bf83e985d/
/raw/ef8528afb70c446ac1c97c8bf83e985d/
ef8528afb70c446ac1c97c8bf83e985d
csharp
C#
3
2019-07-14T16:44:44
True
False
False
/api/public/snipt/37648/
get-number-of-days-between-two-datetime
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">DateTime</span> <span class="n">d1</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">DateTime</span> <span class="n">d2</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="kt">double</span> <span class="n">diff</span> <span class="p">=</span> <span class="p">(</span><span class="n">d1</span> <span class="p">-</span> <span class="n">d2</span><span class="p">).</span><span class="n">TotalDays</span><span class="p">;</span> </span></pre></div> </td></tr></table>
datetime

Text only

Using Reflection to load Microsoft.Web.Administration in PowerShell

1
2
3
4
[System.Reflection.Assembly]::LoadFrom("C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll")
$sm = new-object Microsoft.Web.Administration.ServerManager
$sm.Sites["test2"].Delete()
$sm.CommitChanges()
https://snipt.net/embed/9566fd81d55ab8acabc6f22f3728c31e/
/raw/9566fd81d55ab8acabc6f22f3728c31e/
9566fd81d55ab8acabc6f22f3728c31e
text
Text only
4
2019-07-16T02:45:42
True
False
False
/api/public/snipt/37601/
using-reflection-to-load-microsoftwebadministration-in-powershell
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>[System.Reflection.Assembly]::LoadFrom(&quot;C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll&quot;) </span><span id="L-2"><a name="L-2"></a>$sm = new-object Microsoft.Web.Administration.ServerManager </span><span id="L-3"><a name="L-3"></a>$sm.Sites[&quot;test2&quot;].Delete() </span><span id="L-4"><a name="L-4"></a>$sm.CommitChanges() </span></pre></div> </td></tr></table>
powershell, reflection