Infopath upload attachment

Source: Internet
Author: User
Copyright:Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://zhonglei.blog.51cto.com/1159374/268587
Original article:Http://www.bizsupportonline.net/blog/2010/01/upload-document-sharepoint-infopath-form/By s.y. M. Wong-a-ton This document describes how to use code to extract attachments from an infopath form and upload them to SharePoint.Run the following code to name infopathDocumentFile in the attachment control, uploaded to SharePoint namedMydocuments. The specific operation is to add a button on the form, add the vsta code on the button, and add the following code. In the entire programInfopathattachmentdecoderFor details about how to write this class, refer to Microsoft's official Article http://support.microsoft.com/kb/892730.

// Retrieve the value of the attachment in the infopath form
Xpathnavigator ipformnav = maindatasource. createnavigator ();
Xpathnavigator nodenav = ipformnav. selectsinglenode (
"// My: Document", namespacemanager );

String attachmentvalue = string. empty;
If (nodenav! = NULL &&! String. isnullorempty (nodenav. Value ))
{
Attachmentvalue = nodenav. value;

// Decode the infopath file attachment
Infopathattachmentdecoder dec =
New infopathattachmentdecoder (attachmentvalue );
String filename = dec. filename;
Byte [] DATA = dec. decodedattachment;

// Add the file to a document library
Using (spsite site = new spsite ("http ://Servername"))
{
Using (spweb web = site. openweb ())
{
Web. allowunsafeupdates = true;
Spfolder doclib = web. folders ["mydocuments"];
Doclib. Files. Add (filename, data );
Web. allowunsafeupdates = false;
Web. Close ();
}
Site. Close ();
}
} Note that you need to reference SharePoint DLL in the vsta project and add a reference to Microsoft. SharePoint namespace. Then, give the infopath form full security trust so that the code can access SharePoint resources.

This article is from 51cto. com technical blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.