Results 1 to 5 of 5

Thread: Drag and drop attachment in outlook addin

  1. Default Drag and drop attachment in outlook addin

    Hi All,

    I have created outlook addin for outlook 2003 in vsto-2008. When I have tried to allow property 'allowDrag' to textbox it gives runtime exception "dragdrop registration did not succeed". I have searched on net, got suggestion to use threading.

    Thread t = new Thread(new ThreadStart(ShowForm));
    t.SetApartmentState(ApartmentState.STA);
    t.Start();

    public void ShowForm()
    {

    form.ShowDialog();
    form.Dispose();
    }

    Drag problem solved using thread but it give other problem in my application as follows
    a) When I right click on context menu then form disappear.
    b) Some time application hangs...

    Can I solve this problem without using thread? Because handling thread will almost change my design.

    Regards,
    Nit

  2. #2
    Ken Slovak - [MVP - Outlook] Guest

    Default Re: Drag and drop attachment in outlook addin

    Are you trying to use the Outlook object model from a background thread?
    That's not supported and will crash or hang Outlook. You have to marshal
    that background thread to the main process thread if you are using the
    object model.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "nitwalke@gmail.com" <nitwalkegmail.com.418a5m@invalid> wrote in message
    news:nitwalkegmail.com.418a5m@invalid...
    >
    > Hi All,
    >
    > I have created outlook addin for outlook 2003 in vsto-2008. When I have
    > tried to allow property 'allowDrag' to textbox it gives runtime
    > exception "dragdrop registration did not succeed". I have searched on
    > net, got suggestion to use threading.
    >
    > Thread t = new Thread(new ThreadStart(ShowForm));
    > t.SetApartmentState(ApartmentState.STA);
    > t.Start();
    >
    > public void ShowForm()
    > {
    >
    > form.ShowDialog();
    > form.Dispose();
    > }
    >
    > Drag problem solved using thread but it give other problem in my
    > application as follows
    > a) When I right click on context menu then form disappear.
    > b) Some time application hangs...
    >
    > Can I solve this problem without using thread? Because handling thread
    > will almost change my design.
    >
    > Regards,
    > Nit
    >
    >
    > --
    > nitwalke@gmail.com
    > http://forums.slipstick.com
    >



  3. Default Re: Drag and drop attachment in outlook addin

    Thanks Ken for replay.
    I am not interested to use thread. I want to know, Can DragDrop registration will possible without using thread.I got following error while registering DragDrop event for text box.
    "System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."

    I searched on net and got threading solution. But Can we solve this problem without using thread?

    Quote Originally Posted by Ken Slovak - [MVP - Outlook] View Post
    Are you trying to use the Outlook object model from a background thread?
    That's not supported and will crash or hang Outlook. You have to marshal
    that background thread to the main process thread if you are using the
    object model.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "nitwalke@gmail.com" <nitwalkegmail.com.418a5m@invalid> wrote in message
    news:nitwalkegmail.com.418a5m@invalid...
    >
    > Hi All,
    >
    > I have created outlook addin for outlook 2003 in vsto-2008. When I have
    > tried to allow property 'allowDrag' to textbox it gives runtime
    > exception "dragdrop registration did not succeed". I have searched on
    > net, got suggestion to use threading.
    >
    > Thread t = new Thread(new ThreadStart(ShowForm));
    > t.SetApartmentState(ApartmentState.STA);
    > t.Start();
    >
    > public void ShowForm()
    > {
    >
    > form.ShowDialog();
    > form.Dispose();
    > }
    >
    > Drag problem solved using thread but it give other problem in my
    > application as follows
    > a) When I right click on context menu then form disappear.
    > b) Some time application hangs...
    >
    > Can I solve this problem without using thread? Because handling thread
    > will almost change my design.
    >
    > Regards,
    > Nit
    >
    >
    > --
    > nitwalke@gmail.com
    > http://forums.slipstick.com
    >

  4. #4
    Ken Slovak - [MVP - Outlook] Guest

    Default Re: Drag and drop attachment in outlook addin

    I told you the only solution I know of.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "nitwalke@gmail.com" <nitwalkegmail.com.41ez6x@invalid> wrote in message
    news:nitwalkegmail.com.41ez6x@invalid...
    >
    > Thanks Ken for replay.
    > I am not interested to use thread. I want to know, Can DragDrop
    > registration will possible without using thread.I got following error
    > while registering DragDrop event for text box.
    > "System.InvalidOperationException: DragDrop registration did not
    > succeed. ---> System.Threading.ThreadStateException: Current thread must
    > be set to single thread apartment (STA) mode before OLE calls can be
    > made. Ensure that your Main function has STAThreadAttribute marked on
    > it."
    >
    > I searched on net and got threading solution. But Can we solve this
    > problem without using thread?



  5. Default Re: Drag and drop attachment in outlook addin

    I will give details about my project.
    In ThisAddIn class..

    [STAThread]
    private void NewButtonClick()
    {
    Form frm = new Form();
    frm.ShowDialog();
    }

    and in form class.
    I have created textbox and set AllowDrop=True;
    it gives following error

    System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
    at System.Windows.Forms.Control.SetAcceptDrops(Boolea n accept)
    --- End of inner exception stack trace ---
    at System.Windows.Forms.Control.SetAcceptDrops(Boolea n accept)
    at System.Windows.Forms.Control.OnHandleCreated(Event Args e)
    at System.Windows.Forms.Form.OnHandleCreated(EventArg s e)
    at System.Windows.Forms.Control.WmCreate(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
    at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
    at System.Windows.Forms.Form.WmCreate(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    I put [STAThread] above startup method

    [STAThread]
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
    .
    .
    }

    how should I proceed?

    Quote Originally Posted by Ken Slovak - [MVP - Outlook] View Post
    I told you the only solution I know of.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "nitwalke@gmail.com" <nitwalkegmail.com.41ez6x@invalid> wrote in message
    news:nitwalkegmail.com.41ez6x@invalid...
    >
    > Thanks Ken for replay.
    > I am not interested to use thread. I want to know, Can DragDrop
    > registration will possible without using thread.I got following error
    > while registering DragDrop event for text box.
    > "System.InvalidOperationException: DragDrop registration did not
    > succeed. ---> System.Threading.ThreadStateException: Current thread must
    > be set to single thread apartment (STA) mode before OLE calls can be
    > made. Ensure that your Main function has STAThreadAttribute marked on
    > it."
    >
    > I searched on net and got threading solution. But Can we solve this
    > problem without using thread?

Similar Threads

  1. Outlook addin formregion as a drop down
    By Sanaulah in forum Programming Add-ins Archive
    Replies: 6
    Last Post: 10-22-2009, 09:16 PM
  2. Drag & drop an email to a folder in outlook
    By Fred in forum Outloook General Archives
    Replies: 1
    Last Post: 07-17-2009, 07:08 AM
  3. Implementing Drag and drop events in outlook
    By Ashish in forum Programming Add-ins Archive
    Replies: 7
    Last Post: 07-06-2009, 06:10 AM
  4. Copy or Drag&Drop attachment from Outlook to [Program] Fails
    By steven filg in forum Outloook General Archives
    Replies: 5
    Last Post: 03-12-2009, 08:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts