Click here to Skip to main content
12,758,605 members (31,119 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0 Outlook AddIn
Hi,
How do i copy the active email message selected text in outlook 2007 using C#.net, when the toolbar button is clicked bellow event is fired that event selected text to stored the sql server database how to write the code pls give me any suggestion , i am verify the link but that link <a href="http://www.vbforums.com/showthread.php?t=451995"></a> is VB.net , i have c#.net code pls give me some idea

private void _objToolBarButton_Click(Office.CommandBarButton ctrl, ref bool cancel)

Thank u
RaviChaitanya
Posted 6-Feb-12 1:51am
Updated 6-Feb-12 1:55am
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

private void savenumbers()
{
try
{
Outlook.Application oApp;
Outlook.Explorer oExp;
Outlook.Selection oSel;
object oItem;
long i;
// TODO: On Error GoTo Warning!!!: The statement is not translatable
oApp = new Outlook.Application();
oExp = oApp.ActiveExplorer();
oSel = oExp.Selection;
if ((oSel.Count == 0))
{
System.Windows.Forms.MessageBox.Show("Nothing selected");
return;
}
for (i = 1; i <= oSel.Count; i++)
{
oItem = oSel[i];

DisplayMessage(oItem);
}
}


catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error " + ex.Message.ToString());
}
}
public int outlooksavenumber(string testcopy)
{

int ReturnValue = 0;
ReturnValue = SqlHelper.ExecuteNonQuery(LITRMSConnection, "usp_Outlooksavenumbers",
new SqlParameter("@testcopy", testcopy));

return ReturnValue;
}

void DisplayMessage(object oItem)
{
//Outlook.MailItem oMailItem;
Outlook.MailItem oMail = (Outlook.MailItem)oItem;
//System.Windows.Forms.MessageBox.Show(oMail.Subject);
//System.Windows.Forms.MessageBox.Show(oMail.Body);
string body = oMail.Body;
Outlook.Inspector inspector = oMail.GetInspector;

// Obtain the Word.Document object from the Inspector object
Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;

// Copy the selected objects
string testcopy = "";
testcopy = document.Application.Selection.Text;

outlooksavenumber(testcopy);
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 8 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100