Infopath: How to Solve infopath's problem of uploading multiple attachments

Source: Internet
Author: User
Now let's take a look at the end code section.

The main technical points in the Code Section are infopath attachment decomposition and repeated infopath table operations.

Namespace reference

Usingmicrosoft. Office. infopath;

Using;

Using. xml;

Using. xml. XPath;

Using. Windows. forms;

Using. text;

First, register two button events

publicvoidInternalStartup
    {
      ((ButtonEvent)EventManager.ControlEvents["CTRL12_5"]).ClickedClickedEventHandler(CTRL12_5_Clicked);
      ((ButtonEvent)EventManager.ControlEvents["CTRL18_5"]).ClickedClickedEventHandler(CTRL18_5_Clicked);
    }

The upload button event mainly deals with file splitting and uploading and duplicate table deletion.

Publicvoidctrl12_5_clicked (objectsender, clickedeventargse)
{
// Write code here
Xpathnavigatordomnav = maindatasource. createnavigator;
Xpathnodeiteratorrows = domnav. Select ("/My: myfields/My: Group3/My: group5", namespacemanager );
Xpathnodeiteratorrows1;
Mynamespace = namespacemanager. lookupnamespace ("my ");
While (rows. movenext)
{
Rows1 = domnav. Select ("/My: myfields/My: group6/My: group7", namespacemanager );
Attachment = rows. Current. selectsinglenode ("My: attachment", namespacemanager). value;
Attachmentbytes = convert. frombase64string (Attachment );
Namebufferlen = attachmentbytes [20] * 2;
Filenamebuffer = [namebufferlen];
// Theactualfilenamestartsatposition24
For (I = 0; I <namebufferlen; I)
{
Filenamebuffer [I] = attachmentbytes [24 + I];
}
// Originalfilenameminusthelastcharacter!
Charasciichars = unicodeencoding. Unicode. getchars (filenamebuffer );
Filename = (asciichars );
Filename = filename. sub (0, filename. Length-1 );
//. Gif '/> name. Add (filename );
// Thefileislocatedaftertheheader, whichis24slong
// Plusthelengthofthefilename.
Filecontent = [attachmentbytes. Length-(24 + namebufferlen)];
For (I = 0; I <filecontent. length; I)
{
Filecontent [I] = attachmentbytes [24 + namebufferlen + I];
}
Apws. agilepartsapws = attachment. apws. agileparts;
Savepath = @ "http: // ascentn-Moss: 8080/shared % 20 documents ";
Apws. Credentials =. net. credentialcache. defaultcredentials;
Attachurl = apws. uploadfiletosps2 (savepath + "/" + filename, true, filecontent );
K = 0;
(Rows1.count0)
K = 1;
        
K = rows1.count + 1;
  
Using (xmlwriterwriter = maindatasource. createnavigator. selectsinglenode ("/My: myfields/My: group6", namespacemanager). appendchild)
{
Writer. writestartelement ("group7", mynamespace );
Writer. writeelementstring ("fieldid", mynamespace, K .);
Writer. writeelementstring ("fieldurl", mynamespace, attachurl );
Writer. writeelementstring ("fieldname", mynamespace, filename );
Writer. writeendelement;
Writer. close;
}
        
}
Group2nodescount = rows. count;
Xpathnavigatorfirstgroup2nodenav = domnav. selectsinglenode ("/My: myfields/My: Group3/My: group5 [1]",
Namespacemanager );
Xpathnavigatorlastgroup2nodenav = domnav. selectsinglenode ("/My: myfields/My: Group3/My: group5 [" + group2nodescount. + "]", namespacemanager );
Firstgroup2nodenav. deleterange (lastgroup2nodenav );
}

The deletion event mainly deals with the deletion of document library files and the deletion of duplicate table rows in infopath forms.

Publicvoidctrl18_5_clicked (objectsender, clickedeventargse)
{
// Write code here
Strfileurl = E. Source. selectsinglenode ("/My: myfields/My: group6/My: group7/My: fieldurl", namespacemanager). value;
Spsecurity. runwithelevatedprivileges (delegate
{
Try
{
Using (spsitemysite = spsite ("http: // ascentn-Moss: 8080 "))
{
Mysite. allowunsafeupdates = true;
Spwebwebs = mysite. openweb;
Webs. allowunsafeupdates = true;
Webs. GetFile (strfileurl). Delete;
}
}
Catch (exceptionex)
{
Throwex;
}
});
E. Source. deleteself;
}

The basic thing here is that the infopath form design is not mentioned here.

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.