访问信息路径字段[启用浏览器] [英] access infopath fields [browser-enabled]

查看:65
本文介绍了访问信息路径字段[启用浏览器]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我在sharepoint Server 2010中有一个应用程序页面,并且有一个infopath 2010表单,我想按应用程序页面填写infopath的富文本框字段.

我使用xsd.exe/c/l:CS myschema.xsd语句将其转换为.net类,现在我将填充infopath的richtextbox字段,但无法在其后的代码中填充它. 我已经通过http://www.codeproject.com/KB/sharepoint/InfopathForm.aspx制作了此项目.

hi all.
i have a application page in sharepoint server 2010, and a infopath 2010 form, i want fill rich text box field of infopath by application page.

i use xsd.exe /c /l:CS myschema.xsd statement for convert it to .net class and now i will fill richtextbox field of infopath but i can''t fill it with code behind.
i have producted this project by http://www.codeproject.com/KB/sharepoint/InfopathForm.aspx.

推荐答案

您可以按以下步骤完成此功能:

1.使用日期选择器"字段创建一个InfoPath表单模板.
2.将表单模板发布到SharePoint表单库.
3.转到发布了表单模板的SharePoint表单库,填写新表单,然后将其保存在表单库中.
4.点击表单库中新创建的表单,然后选择发送到>从上下文菜单中下载一个副本,然后将表单本地保存在磁盘上.
5.转到将表单保存在本地磁盘上的位置,然后在记事本中打开它.如您所见,InfoPath表单是XML文件,因此,如果您要以编程方式创建InfoPath表单,则必须编写代码以编程方式生成InfoPath表单的XML,该代码看起来类似于您下载的InfoPath表单的XML,并将表单中字段的值替换为所需的新值.您需要确保的重要一件事是mso-infoPathSolution处理指令中的href属性指向您发布的正确表单模板.
6.打开Microsoft Visual Studio 2005并创建一个新的控制台应用程序项目.
7.导入以下名称空间:

You can accomplish this functionality as follows:

1.Create an InfoPath form template with a Date Picker field.
2.Publish the form template to a SharePoint form library.
3.Go to the SharePoint form library to which you published the form template, fill out a new form, and save it in the form library.
4.Click on the newly created form in the form library, select Send To > Download a Copy from the context menu, and save the form locally on disk.
5.Go to the location where you saved the form on your local disk and open it in Notepad. As you can see, InfoPath forms are XML files, so if you want to programmatically create an InfoPath form, you have to write code to programmatically generate the XML of the InfoPath form, which looks similar to the XML of the InfoPath form you downloaded, and replace the values of fields in the form with the desired new values. An important thing you need to make sure of is that the href attribute in the mso-infoPathSolution processing instruction points to the correct form template you published.
6.Open Microsoft Visual Studio 2005 and create a new Console Application project.
7.Import the following namespaces:

using System.Xml;
using System.IO;
using System.Net;


8.在控制台应用程序的Main方法中放置以下C#代码:


8.Put the following C# code in the Main method of the Console Application:

byte[] infoPathFormData = null;

using (MemoryStream ms = new MemoryStream())
{
using (XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8))
{
// Define the namespace for the form
string myNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-09-02T01:11:44";

writer.WriteStartDocument();

// Create the required processing instructions
writer.WriteProcessingInstruction(
"mso-infoPathSolution", 
"name=\"urn:schemas-microsoft-com:office:infopath:ProgCreateForm:-myXSD-2007-09-02T01-11-44\" solutionVersion=\"1.0.0.2\" productVersion=\"12.0.0.0\" PIVersion=\"1.0.0.0\" href=\"http://servername/formlibname/forms/template.xsn\"");
writer.WriteProcessingInstruction(
"mso-application", 
"progid=\"InfoPath.Document\" versionProgid=\"InfoPath.Document.2\"");

// Create the XML of the main data source of the form
writer.WriteStartElement("my", "myFields", myNamespace);
writer.WriteStartElement("my", "field1", myNamespace);
// Fill the date field with today's date
writer.WriteString(DateTime.Now.ToString("yyyy-MM-dd"));
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}

infoPathFormData = ms.GetBuffer();
ms.Close();
}

// Upload the newly created InfoPath form to SharePoint
if (infoPathFormData != null && infoPathFormData.Length != 0)
{
using (WebClient client = new WebClient())
{
// Set the credentials to be used for upload to SharePoint
client.Credentials = CredentialCache.DefaultCredentials;

// Upload the newly created form to a SharePoint form library
client.UploadData(
@"http://servername/formlibname/newformname.xml", 
"PUT", 
infoPathFormData);
}
}


将上面代码片段中生成XML的代码替换为为您自己的InfoPath表单生成XML的代码.本文中显示的代码不适用于您的InfoPath表单,但特定于本文撰写时使用的InfoPath表单和表单模板.

现在,您应该能够以编程方式从头开始为InfoPath表单创建XML,并将其上传到SharePoint表单库.


Replace the code that generates the XML in the code snippet above with code to generate the XML for your own InfoPath form. The code displayed in this article will not work for your InfoPath form, but is specific to the InfoPath form and form template that were used when this article was written.

You should now be able to programmatically create the XML for an InfoPath form from scratch and upload it to a SharePoint form library.


您可以使用此

这篇关于访问信息路径字段[启用浏览器]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆