infopath:InfoPath 上传多附件解决思路方法

效果图就是这样了下面来看看终点代码部分

  代码部分主要技术点就是infopath附件分解和对infopath重复表操作

  命名空间引用

  usingMicrosoft.Office.InfoPath;

  using;

  using.Xml;

  using.Xml.XPath;

  using.Windows.Forms;

  using.Text;

  首先是注册两个按钮事件

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


  编写上传按钮事件主要处理是文件分解上传以及重复表删除增加

publicvoidCTRL12_5_Clicked(objectsender,ClickedEventArgse)
    {
      //在此处编写代码 
      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=附件.APWS.AgileParts;
        savePath=@"http://ascentn-moss:8080/Shared%20Documents";
        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);
    }




  删除事件主要处理了对文档库文件删除以及infopath表单重复表行删除都是比较基本操作

publicvoidCTRL18_5_Clicked(objectsender,ClickedEventArgse)
    {
      //在此处编写代码
      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;
    }


  到这里基本东西就是这些了有关infopath表单设计这里就不提了
posted @ 2010-08-16 17:49  China2008  阅读(279)  评论(0编辑  收藏  举报