Code Snippets
Ready-to-use code snippets
// Get the desired store
IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForDomain();
// Check if file exists
bool fileExists = isoFile.GetFileNames("TheFile.txt").GetLength(0) != 0);
Extracted and converted original source by Scott Mitchell.
// You can render any ASP.NET control to pure HTML like this:
StringBuilder sb =
new StringBuilder();StringWriter sw =
new StringWriter(sb);HtmlTextWriter htmlTW =
new HtmlTextWriter(sw);cControlToRender.RenderControl(htmlTW);
string
html = sb.ToString();
// And use the output as the body of an HTML mail.
using System.Web.Mail;...
MailMessage msg =
new MailMessage();msg.To = "someone@dotnet-online.com";
msg.From = "whoever@dotnet-online.com";
msg.Subject = "ASP.NET Rendered HTML Mail";
msg.BodyFormat = MailFormat.Html;
msg.Body = html;
...
SmtpMail.Send(msg);
<code>
using
System.DirectoryServices;
...
DirectoryEntry myDirectoryEntry;
myDirectoryEntry =
new DirectoryEntry(@"WinNT://MyDirectoryServer/MyUsername,User");
myDirectoryEntry.Invoke("setPassword", "MyNewPassword");
myDirectoryEntry.CommitChanges();
</code>
After months of searching and a lot of trial-and-error I accidently stepped by Patrick Steele's .NET Blog and his solution that perfectly works with Windows 2000 and higher.
<quote>
I needed to know if one of my COM+ applications was currently running. Some Googling came up with an "ApplicationInstances" collection by interop'ing with the COMAdmin library, but that only works for XP and Win2K3 Server. Of course, I needed this for Win2k.
Some more Googling returned information on the IMtsGrp interface in the COMSvcs library. This works from NT4 through to XP and was just what I needed. I generated a RCW for it and coded my function:
private bool IsRunning(string applicationName)
{
IMtsGrp group = new MtsGrpClass();
for(int i=0; i<group.Count ; i++ )
{
object outEvents;
group.Item(i, out outEvents);
COMEvents eventObj = (COMEvents) outEvents;
if( eventObj.PackageName == applicationName )
return true;
}
return false;
}</quote>
But one problem remains: How do I determine if a COM+ application is running on a remote machine?
I added the new category Code Snippets to my blog where I will put small code fragments you can copy and paste directly into your classes.