Separating attachments from InfoPath 2007 browser enabled forms - InfoPath Dev
in

InfoPath Dev

Separating attachments from InfoPath 2007 browser enabled forms

Last post 03-24-2009 11:42 PM by ligeshkoshy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-04-2009 10:14 PM

    Separating attachments from InfoPath 2007 browser enabled forms

    Hi

    We have a requirement in the project to separate the attachment embedded in the InfoPath 2007 browser enabled form to be saved in a MOSS 2007 document library with only the link between them saved in the InfoPath form to improve performance.

    We need to have the approach like Opening a Excel template or a Web form(aspx page) on button click. Can it be done through XMLFormView , and will it have improved performance than embedding the attachment in the InfoPath 2007 form itself.

    Any input is appreciated.

     

     

    Software Consultant
    MCP, MCTS, CCNA
    India
  • 03-04-2009 11:24 PM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Separating attachments from InfoPath 2007 browser enabled forms

  • 03-24-2009 11:42 PM In reply to

    Re: Separating attachments from InfoPath 2007 browser enabled forms

    Thanks for your replies . I got some workarounds from it and built my solution.

    Workaround

    Add a attachment control in the InfoPath form. I had a submit button which submits the document in a specified document library and returns a link from it which gets added up in a textbox in the InfoPath form . In the design mode the textbox is changed to hyperlink. When it form is deployed we can see the textbox is viewed as a hyperlink.

    Bits of code to detach the file, place it in document library , get a link value to the hyperlink converted textbox.

    char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);string fileName = new string(charFileName);

    fileName = fileName.Substring(0, fileName.Length - 1);

    // The file is located after the header, which is 24 bytes long

    // plus the length of the filename.

    byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];for (int i = 0; i < fileContents.Length; ++i)

    {

    fileContents[i] = attachmentNodeBytes[24 + fnLength + i];

    }

    string SiteAttachURL = _strDocLibURL + strReqID + "_" + fileName;

    Add it to document library

    SPSite siteCol = null;

    SPWeb curSite = null;

    siteCol = new SPSite("url of root site);

    curSite = siteCol.OpenWeb();

    curSite.AllowUnsafeUpdates =
    true;

    curSite.Files.Add(SiteAttachURL, fileContents);

     Add link in the hyperlink converted textbox  

    XPathNavigator nav1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:secContentView/my:secContent/my:secAttachments/my:templateURL", NamespaceManager);

    nav1.SetValue(SiteAttachURL);

    Code to Detach document from the InfoPath attachment control can be follwed from the below link

    http://www.sharepointblogs.com/ssa/archive/2008/01/15/infopath-delete-file-attachments-programmatically-c.aspx

    Please check whether you have appropriate permissions to add a document to the document library and add AllowUnsafeUpdates = true;

    Software Consultant
    MCP, MCTS, CCNA
    India
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.