Hello Hilary
Thanks for the response. But sure your solution will not help me...please find the below code..look at the last line ..
client.UploadData(
@"http://SERVERXXX/IPF/REMAIL/Test - " + Guid.NewGuid() + ".xml",
"PUT", infoPathFormData);
there saving the file as .xml means saving as InfoPath form but I need to save as .PDF..Please help
Microsoft.Office.Interop.Outlook.
Application app = null;Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.
MailItem item = null;Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.
Recipient iRecip = null;
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace(
"MAPI"); iRecip = ns.CreateRecipient("Display Name");if (iRecip.Resolve())
{
inboxFolder = ns.GetSharedDefaultFolder(iRecip,
OlDefaultFolders.olFolderInbox);Console.WriteLine("Folder Name: {0}, EntryId: {1}", inboxFolder.Name, inboxFolder.EntryID);
Console.WriteLine("Num Items: {0}", inboxFolder.Items.Count.ToString());for (int i = 1; i <= inboxFolder.UnReadItemCount; i++)
{
item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i];
Console.WriteLine("Item: {0}", i.ToString());Console.WriteLine("From: {0}", item.SenderName.ToString());
Console.WriteLine("To: {0}", item.ReceivedByName.ToString());Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());Console.WriteLine("Body: {0}", item.Body);if (item.UnRead)
{
item.BodyFormat = OlBodyFormat.olFormatPlain;
/* Code to fill the InfoPath form on fly and save to WSS library */byte[] infoPathFormData = null;using (MemoryStream ms = new MemoryStream())
{
using (XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8))
{
// Define the namespace for the formstring myNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-19T09:12:10";
writer.WriteStartDocument();
// Create the required processing instructionswriter.WriteProcessingInstruction("mso-infoPathSolution","name=\"urn:schemas-microsoft-com:office:infopath:RetrieveEmail:-myXSD-2008-12-19T09-
12-10\" solutionVersion=\"1.0.0.5\" productVersion=\"12.0.0\" PIVersion=\"1.0.0.0\"
href=\"http://SERVERXXX/IPF/REMAIL/Forms/template.xsn\""
);writer.WriteProcessingInstruction("mso-application", "progid=\"InfoPath.Document\"
versionProgid=\"InfoPath.Document.2\""
);
// Create the XML of the main data source of the formwriter.WriteStartElement("my", "myFields", myNamespace);
writer.WriteStartElement(
"my", "eMailDetails", myNamespace);writer.WriteStartElement("my", "eMailFrom", myNamespace);
writer.WriteString(item.SenderName.ToString());
writer.WriteEndElement();
writer.WriteStartElement("my", "eMailTo", myNamespace);
writer.WriteString(item.ReceivedByName.ToString());
writer.WriteEndElement();
writer.WriteStartElement("my", "eMailSubject", myNamespace);
writer.WriteString(item.Subject);
writer.WriteEndElement();
writer.WriteStartElement("my", "dateTime", myNamespace);
writer.WriteString(item.SentOn.ToLongDateString());
writer.WriteEndElement();
writer.WriteStartElement("my", "emailHTMLBody", myNamespace);
writer.WriteString(item.Body.Replace(
"\r\n", Environment.NewLine).Replace("\t", " ").Replace("’", "").Replace("-", ":"));
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
infoPathFormData = ms.GetBuffer();
ms.Close();
}
// Upload the newly created InfoPath form to SharePointif (infoPathFormData != null && infoPathFormData.Length != 0)
{
using (WebClient client = new WebClient())
{
//Set the credentials to be used for upload to SharePointclient.Credentials = new System.Net.NetworkCredential("UserName", "Password",
"Domain");
// Upload the newly created form to a SharePoint form libraryclient.UploadData(@"http://SERVERXXX/IPF/REMAIL/Test - " + Guid.NewGuid() + ".xml", "PUT", infoPathFormData);
}
}
}
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
ns = null;
app =
null;inboxFolder = null;
}