[已解决]使用自定义代码发布InfoPath表单作为管理员批准的模板 [英] [SOLVED] Publishing InfoPath Form with custom code as admin-approved template
问题描述
我还在另一个修复中。这次是通过自定义代码获取我的infopath表单以在我的表单库中工作。这是我编写的代码,用于计算2个日期时间选择器控件之间的差异,它在预览模式下工作正常。但是当我将表单作为管理员管理的模板发布到SharePoint时,结束日期日期时间选择器控件不起作用,因此计算也不起作用。我查看了ULS日志和事件查看器,但找不到任何错误。任何有可能出错的想法的人?谢谢。
I'm in yet another fix. This time its with getting my infopath form with custom code to work in my form library. Here is the code I have written to calculate the difference between 2 date time picker controls and it works fine in the preview mode. But when I publish the form to SharePoint as an admin-managed template, the end date date time picker control doesn't work hence the calculation doesnt work as well. I have viewed the ULS logs and event viewers and I can't find any errors. Anyone with ideas on what might possibly be wrong? Thanks.
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Collections.Generic;
using Microsoft.SharePoint;
namespace Test
{
public partial class FormCode
{
public object res
{
get
{
return FormState["res"];
}
set
{
FormState["res"] = value;
}
}
public object result
{
get
{
return FormState["result"];
}
set
{
FormState["result"] = value;
}
}
public void InternalStartup()
{
EventManager.XmlEvents["/my:myFields/my:group1/my:EndDT"].Changed += new XmlChangedEventHandler(EndDT_Changed);
}
public void EndDT_Changed(object sender, XmlEventArgs e)
{
// Write your code here to change the main data source.
if (e.Operation == XmlOperation.ValueChange)
{
//Retrieve the values for the start and end time
string startTimeValue = e.Site.SelectSingleNode("../my:StartDT",
NamespaceManager).Value;
string endTimeValue = e.Site.SelectSingleNode("../my:EndDT",
NamespaceManager).Value;
if (!String.IsNullOrEmpty(startTimeValue)
&& !String.IsNullOrEmpty(endTimeValue))
{
//Convert the time values to DateTime objects
//TimeSpan startTime = TimeSpan.Parse(startTimeValue);
//TimeSpan endTime = TimeSpan.Parse(endTimeValue);
DateTime startTime;
DateTime endTime;
//string date1 = "2015-03-23 12:34:56";
//string date2 = "2015-03-23 12:34:56";
try
{
startTime = DateTime.Parse(startTimeValue);
endTime = DateTime.Parse(endTimeValue);
//int startTime2 = startTime.Date.Hour;
//int endTime2 = endTime.Date.Hour;
//int a = startTime.Hour;
//int b = endTime.Hour;
TimeSpan diff = endTime.Subtract(startTime);
string dateInput = diff.ToString();
int day = 0, hour = 0, minutes = 0;
try
{
List<string> dateSplit = new List<string>(dateInput.Split('.', ':'));
if (dateSplit.Count == 4)
{
for (int i = 2; i < dateSplit.Count; i++) // Loop with for.
{
day = int.Parse(dateSplit[0].ToString());
hour = int.Parse(dateSplit[1].ToString());
minutes = int.Parse(dateSplit[2].ToString());
}
res = (int)day * 24;
result = (string)res + hour + ":" + minutes;
}
else if (dateSplit.Count == 3)
{
for (int i = 2; i < dateSplit.Count; i++) // Loop with for.
{
day = int.Parse(dateSplit[0].ToString());
hour = int.Parse(dateSplit[1].ToString());
minutes = int.Parse(dateSplit[2].ToString());
}
res = day;
result = res + ":" + hour;
}
}
catch (Exception ek)
{
}
}
catch (FormatException ex)
{
//Retrieve the time difference field node and remove its nil attribute
XPathNavigator nodeNav = e.Site.SelectSingleNode("../my:Duration",
NamespaceManager);
if (nodeNav.MoveToAttribute("nil", NamespaceManager.LookupNamespace("xsi")))
nodeNav.DeleteSelf();
//Retrieve and display the time difference
e.Site.SelectSingleNode("../my:Duration", NamespaceManager).SetValue(result.ToString());
//((TimeSpan)endTime.Subtract(startTime)).Hours.ToString());
//(diff.ToString());
//((TimeSpan)endTime.Subtract(startTime)).Hours.ToString());
}
}
}
}
}
推荐答案
我终于找到了代码无效的原因。我用来将模板上传到SP的帐户没有SP服务器的完全管理权限。
I finally found the reason why the code wasn't working. The account I was using to upload the template to SP didn't have full administrative rights to the SP server.
这篇关于[已解决]使用自定义代码发布InfoPath表单作为管理员批准的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!