コード例 #1
0
        } // GetInfoPathAndStoreDataInList

        private static void AddInfoPathToList(ClientContext clientContext, Web web, Employees emp)
        {
            Console.WriteLine("Adding infopath data to list....");
            List lstEmployees = web.Lists.GetByTitle(listName); // EmployeesConsoleTest
            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem listItem = lstEmployees.AddItem(itemCreateInfo);
            listItem["Title"] = emp.Name;
            listItem["UserID"] = emp.UserID;
            listItem["EmpManager"] = emp.Manager;
            listItem["EmpNumber"] = emp.Number;
            listItem["Designation"] = emp.Designation;
            listItem["Location"] = emp.Locaiton;
            listItem["Skills"] = emp.Skills;

            listItem.Update();
            clientContext.ExecuteQuery();
        } // AddInfoPathToList
コード例 #2
0
        } // AddInfoPathToList

        private static void ReadInfoPathFile(ClientContext clientContext, Web web, ListItem item, out Employees employee)
        {
            Console.WriteLine("Reading InfoPath file " + item["Title"]);
            File ipFile = item.File;
            ClientResult<System.IO.Stream> streamItem = ipFile.OpenBinaryStream();
            clientContext.Load(ipFile);
            clientContext.ExecuteQuery();
            
            System.IO.MemoryStream memStream = new System.IO.MemoryStream();
            streamItem.Value.CopyTo(memStream);
            memStream.Position = 0;

            XmlDocument ipXML = new XmlDocument();            
            ipXML.Load(memStream);
            XmlNamespaceManager ns = new XmlNamespaceManager(ipXML.NameTable);           
            ns.AddNamespace("my", ipXML.DocumentElement.NamespaceURI);

            XPathNavigator empNavigator = ipXML.CreateNavigator();
            employee = new Employees(); 
            employee.Name = empNavigator.SelectSingleNode("/my:EmployeeForm/my:txtName", ns).Value;
            employee.UserID = empNavigator.SelectSingleNode("/my:EmployeeForm/my:txtUserID", ns).Value;
            employee.Manager = empNavigator.SelectSingleNode("/my:EmployeeForm/my:txtManager", ns).Value;
            employee.Number = empNavigator.SelectSingleNode("/my:EmployeeForm/my:txtEmpNumber", ns).Value;
            employee.Designation = empNavigator.SelectSingleNode("/my:EmployeeForm/my:ddlDesignation", ns).Value;
            employee.Locaiton = empNavigator.SelectSingleNode("/my:EmployeeForm/my:ddlCity", ns).Value;

            XmlNodeList nodeSkills = ipXML.SelectNodes("//my:Skill", ns);
            StringBuilder sbSkills = new StringBuilder();
            foreach (XmlNode nodeSkill in nodeSkills)
            {
                XmlNodeList lstSkill = nodeSkill.ChildNodes;
                sbSkills.Append(lstSkill[0].InnerText).Append(",").Append(lstSkill[1].InnerText).Append(";");
            } //foreach (XmlNode nodeSkill in nodeSkills)

            employee.Skills= sbSkills.ToString();
        } // ReadInfoPathFile