Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:32:35+00:00 2026-05-26T07:32:35+00:00

I’m working with WPF and I’m trying to make a drag’n’drop textbox. In this

  • 0

I’m working with WPF and I’m trying to make a drag’n’drop textbox.
In this textbox I want to get the body of an email which I drag from outlook.
The code works but I think I need something to “reset” the ActiveExplorer cause now it only shows the last “NEW” email which I drag into the textbox.

Example:

Drag email 1 -> Textbox – Shows email 1

Drag email 2 -> Textbox – Shows email 2

Drag email 1 -> Textbox – Shows email 2 and email 1 will not be displayed because it already exists in the ActiveExplorer and it will show email 2.

Hope my question is a bit clear to you..
Thanks in advance!

XAML code:

    <TextBox 
    Name="myTextbox"  
    AllowDrop="True" 
    PreviewDragEnter="email_DragEnter"
    PreviewDrop="email_Drop" />

XAML code behind:

    private void email_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
    }

    private void email_Drop(object sender, DragEventArgs e)
    {
        Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
        Outlook.Explorer oExplorer = oApp.ActiveExplorer();
        Outlook.Selection oSelection = oExplorer.Selection;

        foreach (object item in oSelection)
        {
            Outlook.MailItem mi = (Outlook.MailItem)item;
            myTextbox.Text = mi.Body.ToString();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:32:36+00:00Added an answer on May 26, 2026 at 7:32 am

    I moved the declaration of oApp out of DragDrop event as below, and it works as expected.

    void Startup()
    {
        _Outlook = new Outlook.Application();
    }
    
    Outlook.Application _Outlook = null;
    
    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
    }
    
    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        richTextBox1.Text = "";
        Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
        Outlook.Selection oSelection = oExplorer.Selection;
    
        foreach (object item in oSelection)
        {
            Outlook.MailItem mi = (Outlook.MailItem)item;
            richTextBox1.AppendText(mi.Body.ToString() + "\n----------------------------------------\n");
        }
    }
    

    ——–EDIT——–

    OR Is it possible that you display only the last item because of this loop?

    foreach (object item in oSelection)
    {
        Outlook.MailItem mi = (Outlook.MailItem)item;
        myTextbox.Text = mi.Body.ToString(); //<--- Only last items text
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I am trying to get Undo/Redo keyboard shortcuts working in my WPF application (I
I'm working with WPF, and trying to implement a form to receive a Drag
I am trying to make a Numeric only TextBox in WPF and I have
Been trying to find a working implementation of a WPF listview (or listbox) where
I'm working with WPF and I'm developing a complex usercontrol, which is composed of
I can't believe I'm back to this after working with WPF for 3 months
I am working on a WPF application which has a treeview that represents an
I'm trying to make a standard WPF listbox be dynamically filled, and for each
I'm working on a WPF project, and my intention is to make two specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.