Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

C#

Get Embedded Resource

Stream fileStream= Assembly.GetExecutingAssembly().GetManifestResourceStream("NameSpace.FileNameWithExtension");
https://snipt.net/embed/c09658f584e5bcea0f623c463bbc3dc2/
https://snipt.net/raw/c09658f584e5bcea0f623c463bbc3dc2/
c09658f584e5bcea0f623c463bbc3dc2
csharp
C#
1
2016-12-07T18:23:50
True
False
False
/api/public/snipt/41223/
get-embedded-resource
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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">Stream</span> <span class="n">fileStream</span><span class="p">=</span> <span class="n">Assembly</span><span class="p">.</span><span class="n">GetExecutingAssembly</span><span class="p">().</span><span class="n">GetManifestResourceStream</span><span class="p">(</span><span class="s">&quot;NameSpace.FileNameWithExtension&quot;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
reflection

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/
https://snipt.net/raw/9566fd81d55ab8acabc6f22f3728c31e/
9566fd81d55ab8acabc6f22f3728c31e
text
Text only
4
2016-12-08T04:21:58
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

VB.net

Get method Name in stack trace

1
2
3
4
5
6
    Public Shared Function GetMethodName(ByVal index As Integer) As String
        Dim st As New StackTrace
        Dim sf As StackFrame = st.GetFrame(index)
        Dim mb As MethodBase = sf.GetMethod()
        Return String.Format("{0}.{1}", mb.DeclaringType.FullName(), mb.Name())
    End Function
https://snipt.net/embed/86bf6b4e6ac16589d113e12a8a2fd648/
https://snipt.net/raw/86bf6b4e6ac16589d113e12a8a2fd648/
86bf6b4e6ac16589d113e12a8a2fd648
vb.net
VB.net
6
2016-12-06T18:52:55
True
False
False
/api/public/snipt/16957/
get-method-name-in-stack-trace
<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> <a href="#L-5">5</a> <a href="#L-6">6</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">Public</span> <span class="k">Shared</span> <span class="k">Function</span> <span class="nf">GetMethodName</span><span class="p">(</span><span class="k">ByVal</span> <span class="n">index</span> <span class="ow">As</span> <span class="kt">Integer</span><span class="p">)</span> <span class="ow">As</span> <span class="kt">String</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">Dim</span> <span class="n">st</span> <span class="ow">As</span> <span class="k">New</span> <span class="n">StackTrace</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">Dim</span> <span class="n">sf</span> <span class="ow">As</span> <span class="n">StackFrame</span> <span class="o">=</span> <span class="n">st</span><span class="p">.</span><span class="n">GetFrame</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">Dim</span> <span class="n">mb</span> <span class="ow">As</span> <span class="n">MethodBase</span> <span class="o">=</span> <span class="n">sf</span><span class="p">.</span><span class="n">GetMethod</span><span class="p">()</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">Return</span> <span class="kt">String</span><span class="p">.</span><span class="n">Format</span><span class="p">(</span><span class="s">&quot;{0}.{1}&quot;</span><span class="p">,</span> <span class="n">mb</span><span class="p">.</span><span class="n">DeclaringType</span><span class="p">.</span><span class="n">FullName</span><span class="p">(),</span> <span class="n">mb</span><span class="p">.</span><span class="n">Name</span><span class="p">())</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">End</span> <span class="k">Function</span> </span></pre></div> </td></tr></table>
reflection, stacktrace
Copyrighted, illegal, or inappropriate content? Email [email protected].