How to retrive Outlook message when it has been drop on a form

dotnet framework


  • 1. InvalidCastException: QueryInterface for interface ... failed
    I am trying to access a managed com object created in VC6. I have created a ASP.Net form and have added a COM Reference to the project. This creates a for the project. When I run the form I recieve an exception: InvalidCastException: QueryInterface for interface ... xxx. ... failed, for the called com interface I have created a console app, useing the same steps to create the CCW. In this case, the app functions with out a problem. The problem appears to be in ASP.NET. If anyone has any insights, they would be appreciated Thank
  • 2. marshal array of structure into a com component
    Hi two questions, 1. how to debug trace into the com componet developed using vc++ 6? I had the enable unmanaged debugging set to true in c# project 2. what's the correct way to pass an array of structure into a com method. below is what I have so far and it is not working Any help is appreaciated Michae I have a COM component which has a method like thi getdata(int num, mystruct** structarr the structarr is an array of structure. in the c# program, I use the following code to call the method getdat public IntPtr Marshalptr(mystruct[] arr int size=Marshal.sizeOf(arr[0]) IntPtr buf=Marshal.AllocCoTaskMem(arr.length*size) int offset=0 foreach(mystruct item in arr marshal.StructuretoPtr(item, (IntPtr)(but.ToInt32()+offset), true) offset+=size return buf the IntPtr buf=Marshalptr(myarray) comclass.getdata(3, buf) now when I run the code I got an COMException I suspect that problem lies in the marsheling, but dont' know how to trace it

How to retrive Outlook message when it has been drop on a form

Postby Marek Suski » Sat, 16 Dec 2006 16:42:57 GMT


I am working on a application written in C# (.NET 1.1). I have to implement 
functionality that allow users to drag a e-mail from Outlook onto our app. 
Using following code I am able to get e-mail filename but I get null when 
retriving data in "FileContents" structure. Can you help me in retriving 
message content with attachments?

// set up to obtain the FileGroupDescriptor
// and extract the file name
Stream theStream = (Stream) nseDataObject.GetData("FileGroupDescriptor");
byte [] fileGroupDescriptor = new byte[512];
// used to build the filename from the FileGroupDescriptor block
StringBuilder fileName = new StringBuilder("");
// this trick gets the filename of the passed attached file
for(int i=76; fileGroupDescriptor[i]!=0; i++) {

// put the zip file into the temp directory
string theFile = Path.Combine("c:\\", 

MessageBox.Show("'" + theFile + "'");

try {
    if (File.Exists(theFile))

try {
  // get the actual raw file into memory
  MemoryStream ms = (MemoryStream) nseDataObject.GetData("FileContents", 
  FileStream fs = new FileStream(theFile, FileMode.Create);
} catch (Exception e) {

Best regards

Marek Suski 

Similar Threads:

1.I am having difficulty sending message with an excel attachment (3

I get an error message that a server time out because the message is too 
large. I have increased the timeout . I also have an icon when I hit send 
that states "Microsoft Outlook synchronizing folders seems to run an 
inordinate amount of time. Any Suggestions?

2.I am having trouble encrypting e-mail messages

I followed the directions for digitally signing and encrypting e-mails. I 
sent the certificate to a friend, had him store it in my contact/certificate, 
but I can't send encrypted messages. I get an error saying the user doesn't 
have a certificate or theirs a conflict in encryption methods.

Any ideas?

3.retrive preselected value in second drop down list from the first drop down list

here is my scenario, I create a drop down list in itemtemplate.(that
drop down is created from db), after user
click edit command, my ideal plan is have another drop down list in
edititemtemplate with preselected value from
the previous drop down list, so far I can only achieved with the
regular drop down list in edititemtemplate with no preselected value
from previous one. anyone can help me.
thanks in advance. below is my current sample code.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">

	Dim objConnection As SqlConnection
	Dim myDataReader As SqlDataReader

    Sub Page_Load(Sender As Object, E As EventArgs)
		' Set up our connection.
        objConnection = New SqlConnection("Data Source=sql;Initial
Catalog=pub;User Id=xxx;Password=xxxxx;")


		If Not IsPostBack Then
        End If

    End Sub

	Sub LoadDataFromDB()
        Dim objCommand As SqlCommand

        ' Create new command object passing it our SQL query and
telling it which connection to use.
        objCommand = New SqlCommand("SELECT * FROM Educationtraining
WHERE Username = 'weifon888';", objConnection)

		' Open the connection, execute the command, and close the connection.
		myDataReader =
	End Sub

    Sub DataBindGrid()
        DBEditDataGrid.DataSource = myDataReader
    End Sub

    Sub DBEditDataGrid_Edit(Sender As Object, E As
        DBEditDataGrid.EditItemIndex = E.Item.ItemIndex
    End Sub

    Sub DBEditDataGrid_Cancel(Sender As Object, E As
        DBEditDataGrid.EditItemIndex = -1
    End Sub

    Sub DBEditDataGrid_Update(ByVal Sender As Object, ByVal E As
        ' Since the textboxes are autogenerated we don't know their
names, but we do know their positions.
        Dim Tempdroplist As DropDownList
        Dim Tempdropvalue As String

        Dim strUser As String = E.Item.Cells(0).Text
        Dim certother As TextBox = E.Item.Cells(1).Controls(0)
        Dim strcertother = Replace(certother.Text, "'", "`")

        Tempdroplist = E.Item.FindControl("teachercert")
        Tempdropvalue = Tempdroplist.SelectedItem.Value


        ' Update the appropriate record in our database.
        Dim objCommand As SqlCommand
        Dim strSQLQuery As String

        ' Build our update command.
        strSQLQuery = "UPDATE Educationtraining SET Certother = '" &
strcertother & "' WHERE Username = 'johndoe'"

        ' Create new command object passing it our SQL query and
telling it which connection to use.
        objCommand = New SqlCommand(strSQLQuery, objConnection)

        ' Close our open DataReader

            ' Execute the command

        Catch Ex As Exception

        End Try

        ' Refresh our copy of the data

        ' Reset our current edit item and rebind the grid
        DBEditDataGrid.EditItemIndex = -1
    End Sub


<title>Modify User Profile</title>
<script language="javascript" type="text/javascript">

<form id="Form1" runat="server">

<asp:DataGrid id="DBEditDataGrid" runat="server"
	BorderWidth = "1px" CellSpacing = "2" CellPadding = "2"
	HeaderStyle-Font-Bold = "True"

 	OnEditCommand   = "DBEditDataGrid_Edit"
	OnCancelCommand = "DBEditDataGrid_Cancel"
	OnUpdateCommand = "DBEditDataGrid_Update"

	AutoGenerateColumns = "False"
		<asp:BoundColumn HeaderText="Username"   DataField="Username"
ReadOnly="True" />
		<asp:BoundColumn HeaderText="Cert Other"      DataField="Certother"

	    <asp:TemplateColumn FooterText="test" HeaderText="dropdown">

                    <asp:DropDownList ID="teachercert" runat="server">


                <asp:DropDownList ID="DropDownList1" runat="server"
DataValueField="Teachercert" Enabled="False" AutoPostBack="True">
ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:testConnectionString %>"
                    SelectCommand="SELECT [Teachercert] FROM

			HeaderText = "Edit"
			EditText   = "Edit & Continue"
			CancelText = "Cancel"
			UpdateText = "Update & Continue"

    <HeaderStyle Font-Bold="True" />


4.Attach An outlook message to an outlook message

How do I attach an outlook email message as an attachment within
another outlook email message.

Right now I am using the following code.  But I was wondering if there
is a better way to do this without using a file that needs to be
deleted later.

private MailMessage addAttachment(MailMessage Mail, MailItem item)
                string path "Messages\\message" + message_id+ ".MSG";
                Mail.IsBodyHtml = true;
                System.Net.Mail.Attachment attach = new
                attach.Name = "OriginalMessage.MSG";

5.Drag & Drop of Outlook message + attachments to VB.Net form

Does anyone know how to drag&drop a message with attachments from Outlook
(2002 or 2003) in to a VB.Net windows form.
This is really stumping me.  I've spent a fair amount of time trying to find
a solution on the internet, with limited success.

I do have code to drag an attachment directly from Outlook to a form, but
not a whole message.
I want to have access to an object reprensenting the message so I can bust
out the message and attachments individually.

I have implemented a solution involving dragging the e-mail message from
Outlook to the desktop, then from the desktop to the windows form, but the
users don't want to do that and I don't think they should have to.

I've seen libraries and code that seem to make this easy using VB6, C++, or
COM, but almost nothing in .Net except simple examples of either files or
tree items, not Outlook e-mails directly onto VB.Net Winforms.

Any help appreciated.
Dave Anderson.

6. Drag Drop Messages Form Outlook

7. Drag & Drop Outlook.MailItem to a Windows.Forms.Form and save it

8. Drag and Drop an attachment from an Outlook message

Return to dotnet framework


Who is online

Users browsing this forum: No registered users and 95 guest