我的共享点网站上有一个表单库.以编程方式我需要填写一些字段.我能这样做吗?如果有人知道请提供一些示例代码.首先,我需要检索infopath文档,然后我需要填写字段.
小智 6
axel_c发布的内容非常接近.这里有一些清理和验证的工作代码......
public static void ChangeFields()
{
    //Open SharePoint site
    using (SPSite site = new SPSite("http://<SharePoint_Site_URL>"))
    {
        using (SPWeb web = site.OpenWeb())
        {
            //Get handle for forms library
            SPList formsLib = web.Lists["FormsLib"];
            if (formsLib != null)
            {
                foreach (SPListItem item in formsLib.Items)
                {
                    XmlDocument xml = new XmlDocument();
                    //Open XML file and load it into XML document
                    using (Stream s = item.File.OpenBinaryStream())
                    {
                        xml.Load(s);
                    }
                    //Do your stuff with xml here. This is just an example of setting a boolean field to false.
                    XmlNodeList nodes = xml.GetElementsByTagName("my:SomeBooleanField");
                    foreach (XmlNode node in nodes)
                    {
                        node.InnerText = "0";
                    }
                    //Get binary data for new XML
                    byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(xml.OuterXml);
                    using (MemoryStream ms = new MemoryStream(xmlData))
                    {
                        //Write data to SharePoint XML file
                        item.File.SaveBinary(ms);
                    }
                }
            }
        }
    }
}