Default All Day Event to Check/Yes

爷,独闯天下 提交于 2019-12-23 01:52:55

问题


Thanks for the great help. Another question. How do I set my "All Day Event" field on the calendar to default to "Checked/Yes?" If we can set the default on All Day Event to Yes, is there a way to hide the time fields (keep the date fields - just no time fields)? I'd also like to hide the "Workspace" field as well (if possible).

Thank You

Dave M


回答1:


If you have access to run code on your server, I've run this from a console application and it worked like a charm:

using(SPSite site = new SPSite("http://yoursite"))
{
  using(SPWeb web = site.OpenWeb())
  {
    SPList list = web.Lists["your list name"];
    SPContentType ct = list.ContentTypes["Event"];
    SPFieldLink fieldLink = ct.FieldLinks["fAllDayEvent"];
    Type type = typeof(SPFieldLink);
    PropertyInfo pi = type.GetProperty("Default", BindingFlags.NonPublic | BindingFlags.Instance);
    pi.SetValue(fieldLink, "1", null);
    ct.Update();
  }
} 

Source: http://pholpar.spaces.live.com/blog/cns!2CD45589973F2849!131.entry

Only modification we had to make was the SPFieldLink, the examples uses All Day Event, our lists used fAllDayEvent.

The only other way I've seen work is to modify the list's CAML (Example).

Oh, and we hid the Workspace field using Javascript:

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("hideFields");

function fc(FieldName) {
   var arr = document.getElementsByTagName("!");

   for (var i=0;i < arr.length; i++ ) {
      if (arr[i].innerHTML.indexOf(FieldName) > 0) { return arr[i]; }
   }
}

function hideFields() {
   control = fc("Workspace");
   control.parentNode.parentNode.style.display="none";
}
</script>

Source: http://sharepointsherpa.com/2008/08/26/sharepoint-2007-hiding-fields-on-newformaspx-and-editformaspx-the-easy-way/



来源:https://stackoverflow.com/questions/1969697/default-all-day-event-to-check-yes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!