Click here to Skip to main content
12,944,121 members (52,227 online)
Rate this:
 
Please Sign up or sign in to vote.
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 0:51am
Updated 6-Feb-12 0: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
OriginalGriff 4,653
CHill60 2,970
Maciej Los 2,388
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web01 | 2.8.170518.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