Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Feb 7, 2011

C# & Outlook: Insert image in email body

Haven't posted in a while...I blame it on being lazy. Which is not a bad thing, I always maintain a lazy IT guy is a damn effective IT guy. But I'm veering off topic now.

Figured something out today that might be useful. As you may know there are a few ways of sending mail with your C# app. You can use straight SMTP or you can integrate with various other email clients. The nice feature of the latter method being you'll have a record of the email in your Sent Items. By the way I use Outlook 2007 so for the purpose of this article. Setting up the basic integration is pretty easy so I'm gonna skip that - have a look at http://support.microsoft.com/kb/310262 for info on how it works. Make sure you use an HTML body type. My problem was getting an image (in my case, logo) into the body of the email. It turned out to be as easy as referencing an image in the file system in an img tag, for example:

<img src="" + Application.StartupPath + "\Images\logo.png" + "" align='baseline' border='0' />

Till next time, whenever that may be.

Oct 14, 2010

Building a C# context menu at runtime

I know this is a very basic topic, but I'm pretty sure someone will find a use for it.
This example takes a result set (res.Rows) and builds a context menu with hyperlinks loaded in the tag property. When you click on the menu item, it that loads the link in a webbrowser control. Remember to set the context menu property of the control you want to associate the menu with. The code is self-explanatory.

foreach (DataRow r in res.Rows)
{
ToolStripMenuItem mnuItem = new ToolStripMenuItem();

mnuItem.Text = r[1].ToString();
mnuItem.Tag = @"http://serverIP/website/" + r[3].ToString();
mnuItem.Image = Properties.Resources.ImageName;

mnuItem.Click += new EventHandler(ContextMenuItemClick);
cmnuOptions.Items.Add(mnuItem);
}


private void ContextMenuItemClick(object sender, EventArgs e)
{
ToolStripMenuItem clicked = sender as ToolStripMenuItem;
webReferral.Navigate(clicked.Tag.ToString());
}

.Net Webbrowser control memory leak

If you are wondering why your .net webbrowser controls are drilling your RAM, then this article is for you.


Mike_T2E's code did the trick for me.

Nov 3, 2008

How to: Remove Duplicates from C# ListBox

i must admit i quite a lazy coder so if i can find a method online that i can bend to my will im stoked. every now and again i have to write my own unfortunately...
this is a simple snippet to remove duplicates from a ListBox in C# using an ArrayList. i run this method everytime i add new items.
use it, dont use it....

private void CheckDuplicates()
 {

            int r = ListBox.Items.Count;
            ArrayList newList = new ArrayList();

            //Load all Items into temp array
           string[] temp = new string[r];
            for (int i = 0; i < r; i++)
            {
                temp[i] = ListBox.Items[i].ToString();
            }

            //Add unique items to new ArrayList
            foreach (string ts in temp)
            {
                if (!newList.Contains(ts))
                {
                    newList.Add(ts);
                }
            }

            ListBox.Items.Clear();
            foreach (string ns in newList)
            {
                ListBox.Items.Add(ns.ToString());
            }

  }