help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library - InfoPath Dev
in

InfoPath Dev

help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

Last post 04-30-2010 05:32 AM by pankajJ. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 02-12-2009 09:31 AM

    help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    hi friends..

    Now am working on typical task which needs your help & guidance..here is my scenario

    1) Extract unread e-mail item

    2) Retrieve e-mail field value

    3) Create InfoPath form on fly

    4) Fill in the e-mail field values into InfoPath form

    5) Submit InfoPath form as PDF into WSS form library

    this article helped me till step 4 www.bizsupportonline.net/.../programmatically-create-infopath-form-console-app.htm

    I am now strucked at step 5..please help..

  • 02-17-2009 08:48 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    There is a sample here for exporting a form to PDF -- please note, it requires your form to be full trust.

    Hilary Stoupa

  • 02-18-2009 03:27 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    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 form

    string myNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-19T09:12:10";

    writer.WriteStartDocument();

    // Create the required processing instructions

    writer.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 form

    writer.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 SharePoint

    if (infoPathFormData != null && infoPathFormData.Length != 0)

    {

    using (WebClient client = new WebClient())

    {

    //Set the credentials to be used for upload to SharePoint

    client.Credentials = new System.Net.NetworkCredential("UserName", "Password",

    "Domain");

    // Upload the newly created form to a SharePoint form library

    client.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;

    }

     

     

  • 02-18-2009 08:59 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    Right, your current code is uploading the xml file to the library. You'll need to create the pdf and then upload that instead....

    Hilary Stoupa

  • 02-19-2009 01:35 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    hello..

    Yes its true..

    I tried creating the .PDF file using iTextSharp, but no luck. Please help.

    Note : Your solution needs an infopath form - but I do not have any infopath form here..just have .XML file 

  • 02-23-2009 03:40 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

     

    Got it..

    First uploaded the InfoPath XML file to some folder, then

    a) Retrieve the file

    b) Open the file

    c) Export to PDF

    d) save in WSS form library..below is the continuation code

    Microsoft.Office.Interop.InfoPath.Application appT = new Microsoft.Office.Interop.InfoPath.Application();

    XDocument xDoc = appT.XDocuments.Open(@"\\SERVERXXX\temp\Test - " + nwGuid + ".xml",

    (int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);

    // Exporting the .Pdf file to WSS form library

    xDoc.View.Export(@"\\SERVERXXX\WSSFL\FL1\Test - " + nwGuid + ".pdf", "PDF");

    appT.Quit(true);

    appT = null;

  • 11-03-2009 09:23 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

    Does this work on Browser Enabled form??

  • 04-30-2010 05:32 AM In reply to

    Re: help needed on - Create & fill InfoPath form on FLY and save as PDF in WSS library

     Forum Not found error!

    Help!

    -Pankaj
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.