Drag and drop attachment in outlook addin

Status
Not open for further replies.
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
 
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.

"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
> >
 
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?




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.




--


















"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

>

>
 
I told you the only solution I know of.

"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?
 
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(Boolean accept)
--- End of inner exception stack trace ---
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmCreate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(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?




I told you the only solution I know of.




--


















"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?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
R PST->Outlook.com (Import vs Drag-n-Drop methods Using Outlook.com accounts in Outlook 2
J Can Click to Drag Custom Form Field But Cannot Drop When Designing in Outlook 2007 Outlook VBA and Custom Forms 2
K Cannot consistently drag and drop .msg files into Outlook 2010 Using Outlook 0
F Tumblr - Drag & Drop files (pictures) into Outlook? Using Outlook 12
C Cannot drag and drop or create folder in PST file folders Using Outlook 1
L Copying Emails using drag and drop Using Outlook 2
V Drag and drop into Outlook folders Using Outlook 2
T drag drop/opening drop down/single click acts like double/highlighting Using Outlook 7
R Outlook 2007 - drag drop email to Explorer Using Outlook 1
J Problem using drag and drop to attach an html email in Outlook 2010 Using Outlook 18
H Drag and Drop Outlook mails into a Windows Form Control with eml extension Outlook VBA and Custom Forms 1
M Drag and drop Outlook VBA and Custom Forms 1
S Drag-and-drop to Custom Task Pane Outlook VBA and Custom Forms 2
A Implementing Drag and drop events in outlook Outlook VBA and Custom Forms 7
P Drag and Drop mails from Outlook to Clarion6 Application Outlook VBA and Custom Forms 5
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
S Renaming while drag and dropping to file Using Outlook 1
B Right click-drag no longer creates hyperlinks Using Outlook 2
T Can not drag e-mails from search to folders Using Outlook 1
S cannot drag emails to personal folders BCM (Business Contact Manager) 1
J How to create a drop down user defined field that will appear on an inbox view Outlook VBA and Custom Forms 8
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
Z See "Change View" Drop Down as a List? Using Outlook 1
Y Outlook Task View - Table Format - Customize Reminder Time to Drop-Down Selection Using Outlook 2
D BCM 2013 not functioning as BCM 2010 Example no drop down for communications history Using Outlook 0
M Same file "stuck" on top of file list in "Attach File" drop down Using Outlook 4
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
P BCM 2013 Contacts Form Drop Down Box Bug BCM (Business Contact Manager) 1
P Field in Forms displayed depending on the Item chosen from drop-down-list BCM (Business Contact Manager) 1
M Add custom locations to Outlook Forms "Look In:" drop-down list Using Outlook 5
M How do I link a drop down box to a percent complete box Using Outlook 4
R Display multiple accounts as drop down in the from field in New Mail Using Outlook 1
S Outlook addin formregion as a drop down Outlook VBA and Custom Forms 6
S RE: Template with drop down Outlook VBA and Custom Forms 3
C Drop Down Box in Email Template Outlook VBA and Custom Forms 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
Owl Export Outlook PDF Attachment as JPG? Outlook VBA and Custom Forms 4
Timmon Remove just one attachment before AutoForward Outlook VBA and Custom Forms 0
P File Picker for attachment Outlook VBA and Custom Forms 0
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
N File Picker for attachment Outlook VBA and Custom Forms 2
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
G Save attachment run a script rule Outlook VBA and Custom Forms 0
M Autoforward just attachment OR just body. Outlook VBA and Custom Forms 0
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10

Similar threads

Back
Top