Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 6-Feb-12 0:55am
v4

1 solution

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);
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900