I am building a Team Outlook Calendar from our AD/Exchange binding the scheduler control to a DataTable from codebehind. My ResourceType is bound to an XmlDataSource with the values of the team members. I am receiving and error on the Schedule.DataBind();
Could not find ResourceType selected for grouping. Please, check that the GroupBy attribute is properly set and a ResourceType with the same name exists.
Can someone help, here is the code:
Could not find ResourceType selected for grouping. Please, check that the GroupBy attribute is properly set and a ResourceType with the same name exists.
Can someone help, here is the code:
| <form id="Form1" method="post" runat="server"> | |
| <ajax:ScriptManager ID="ScriptManager" runat="server" /> | |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> | |
| <AjaxSettings> | |
| <telerik:AjaxSetting AjaxControlID="RadScheduler1"> | |
| <UpdatedControls> | |
| <telerik:AjaxUpdatedControl ControlID="RadScheduler1" LoadingPanelID="RadAjaxLoadingPanel1" /> | |
| </UpdatedControls> | |
| </telerik:AjaxSetting> | |
| </AjaxSettings> | |
| </telerik:RadAjaxManager> | |
| <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="30" BackColor="#E0E0E0" InitialDelayTime="500"> | |
| <asp:Image ID="Image1" Style="margin-top: 200px" runat="server" ImageUrl="~/controls/Radcontrols/Ajax/Skins/Default/loading.gif" | |
| BorderWidth="0px" AlternateText="Loading"></asp:Image> | |
| </telerik:RadAjaxLoadingPanel> | |
| <div class="RadScheduler_Mac" style="background: transparent; width: 750px;"> | |
| <div class="headerTop"> | |
| Open System Team Calendar | |
| </div> | |
| </div> | |
| <telerik:RadScheduler | |
| runat="server" | |
| ID="RadScheduler1" | |
| Width="750px" | |
| Skin="Mac" | |
| SelectedView="ResourceView" | |
| GroupBy="Members" | |
| DayStartTime="07:00:00" | |
| DayEndTime="18:00:00" | |
| TimeZoneOffset="-05:00:00" | |
| DataKeyField="NameID" | |
| DataSubjectField="Subject" | |
| DataStartField="StartTime" | |
| DataEndField="EndTime" | |
| DataRecurrenceField="RecurrenceRule" | |
| DataRecurrenceParentKeyField="RecurrenceParentID"> | |
| <ResourceTypes> | |
| <telerik:ResourceType | |
| KeyField="NameID" | |
| Name="Members" | |
| TextField="NameDesc" | |
| ForeignKeyField="NameID" | |
| DataSourceID="XmlDsResources" /> | |
| </ResourceTypes> | |
| </telerik:RadScheduler> | |
| <asp:XmlDataSource id="XmlDsResources" DataFile="~/os/TeamCalendarResources.xml" runat="server"/> | |
| </form> |
| Imports System.Net | |
| Imports System.IO | |
| Imports System.XML | |
| Imports System.Data | |
| Imports System.Configuration | |
| Imports System.Security.Cryptography.X509Certificates | |
| Imports System.DirectoryServices | |
| Partial Class os_TeamCalendar | |
| Inherits System.Web.UI.Page | |
| Const errorLevel As Integer = 2 ' 2 = verbose, 1 = concise | |
| Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load | |
| ' sharing calendar must be set to reviewer http://office.microsoft.com/en-us/outlook/HP011111491033.aspx | |
| If (Not IsPostBack) Then | |
| RadScheduler1.SelectedDate = Today | |
| Dim dt As New DataTable() | |
| dt.Columns.Add("StartTime", System.Type.GetType("System.DateTime")) | |
| dt.Columns.Add("EndTime", System.Type.GetType("System.DateTime")) | |
| dt.Columns.Add("NameID", System.Type.GetType("System.String")) | |
| dt.Columns.Add("Name", System.Type.GetType("System.String")) | |
| dt.Columns.Add("Location", System.Type.GetType("System.String")) | |
| dt.Columns.Add("Subject", System.Type.GetType("System.String")) | |
| dt.Columns.Add("Status", System.Type.GetType("System.String")) | |
| dt.Columns.Add("Type", System.Type.GetType("System.String")) | |
| dt.Columns.Add("RecurrenceRule", System.Type.GetType("System.String")) | |
| dt.Columns.Add("RecurrenceParentID", System.Type.GetType("System.Int32")) | |
| Dim strUsers As String = System.Configuration.ConfigurationManager.AppSettings("Usernames") | |
| Dim arrUsers() As String = strUsers.Split(",") | |
| Dim strUser As String | |
| For Each strUser In arrUsers | |
| LookUpCalendar(strUser, RadScheduler1.SelectedDate, dt) | |
| Next | |
| RadScheduler1.DataSource = dt | |
| RadScheduler1.DataBind() | |
| Else | |
| End If | |
| End Sub | |
| Sub LookUpCalendar(ByVal Name As String, ByVal dDate As DateTime, ByRef dt As DataTable) | |
| Dim strURL As String = "http://" & System.Configuration.ConfigurationManager.AppSettings("EMailServer") & "/exchange/" & Name & "/calendar/" | |
| Dim strRequest As String = "<?xml version=""1.0""?>" & _ | |
| "<g:searchrequest xmlns:g=""DAV:"">" & _ | |
| "<g:sql>SELECT ""urn:schemas:calendar:location"", ""urn:schemas:httpmail:subject"", " & _ | |
| """urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", " & _ | |
| """urn:schemas:calendar:busystatus"", ""urn:schemas:calendar:instancetype"" " & _ | |
| "FROM Scope('SHALLOW TRAVERSAL OF """ & strURL & """') " & _ | |
| "WHERE NOT ""urn:schemas:calendar:instancetype"" = 1 " & _ | |
| "AND ""DAV:contentclass"" = 'urn:content-classes:appointment' " & _ | |
| "AND ""urn:schemas:calendar:dtstart"" > '" & _ | |
| String.Format("{0:yyyy/MM/dd}", dDate) & " 00:00:00' " & _ | |
| "AND ""urn:schemas:calendar:dtend"" < '" & _ | |
| String.Format("{0:yyyy/MM/dd}", dDate.AddDays(1)) & " 00:00:00' " & _ | |
| "ORDER BY ""urn:schemas:calendar:dtstart"" ASC" & _ | |
| "</g:sql></g:searchrequest>" | |
| '0 = " Instance type: 0-Single appointment<br>" | |
| '1 = " Instance type: 1-Master recurring appointment<br>" | |
| '2 = " Instance type: 2-Single instance, recurring appointment<br>" | |
| '3 = " Instance type: 3-Exception to a recurring appointment<br>" | |
| Dim strStatusText As String = "" | |
| Dim Status As Integer | |
| Dim ResponseXmlDoc As XmlDocument = SendRequest("SEARCH", strURL, strRequest, strStatusText, Status) | |
| AddToSchedule(ResponseXmlDoc, Name, dt) | |
| 'Display the results. | |
| If (Status >= 200 And Status < 300) Then | |
| 'AddInfo("<br>" & Name & " " & "Result = " & Status & ": " & strStatusText, 2) | |
| ElseIf Status = 401 Then | |
| 'AddInfo("<br><font color='red'>Permission denied!</font>", 1) | |
| 'AddInfo("<br><font color='red'>Check your permissions for this item.</font>", 2) | |
| Else | |
| 'AddInfo("<br><font color='red'>Request failed.</font>", 1) | |
| 'AddInfo("<br><font color='red'>Result = " & Status & ": " & strStatusText & "</font>", 2) | |
| End If | |
| End Sub | |
| Sub AddToSchedule(ByVal ResponseXmlDoc As System.Xml.XmlDocument, ByVal Name As String, ByRef dt As DataTable) | |
| ' Build a list of the DAV:href XML nodes, corresponding to the folders | |
| ' in the mailbox. The DAV: namespace is typically assigned the a: prefix in the XML response body. | |
| If (ResponseXmlDoc Is Nothing) Then Return | |
| Dim HrefNodes As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("a:href") | |
| ' Build a list of the urn:schemas:httpmail:subject XML nodes, | |
| ' The urn:schemas:httpmail: namespace is typically assigned the e: prefix in the XML response body. | |
| Dim SubjectNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("e:subject") | |
| ' Build a list of the urn:schemas:calendar:location XML nodes, | |
| ' The urn:schemas:calendar: namespace is typically assigned the d: prefix in the XML response body. | |
| Dim LocationNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("d:location") | |
| ' Build a list of the urn:schemas:calendar:dtstart XML nodes, | |
| Dim StartTimeNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtstart") | |
| ' Build a list of the urn:schemas:calendar:dtend XML nodes, | |
| Dim EndTimeNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtend") | |
| ' Build a list of the urn:schemas:calendar:busystatus XML nodes, | |
| Dim BusyStatusNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("d:busystatus") | |
| ' Build a list of the urn:schemas:calendar:instancetype XML nodes, | |
| Dim InstanceTypeNodeList As System.Xml.XmlNodeList = ResponseXmlDoc.GetElementsByTagName("d:instancetype") | |
| ' Loop through the returned items (if any). | |
| If SubjectNodeList.Count > 0 Then | |
| Dim i As Integer | |
| For i = 0 To SubjectNodeList.Count - 1 | |
| Dim dr As DataRow = dt.NewRow() | |
| dr("Subject") = SubjectNodeList(i).InnerText | |
| dr("Location") = LocationNodeList(i).InnerText | |
| dr("StartTime") = DateTime.Parse(StartTimeNodeList(i).InnerText) | |
| dr("EndTime") = DateTime.Parse(EndTimeNodeList(i).InnerText) | |
| dr("Status") = BusyStatusNodeList(i).InnerText | |
| dr("NameID") = Name | |
| dr("Name") = Name | |
| dr("Type") = InstanceTypeNodeList(i).InnerText | |
| dr("RecurrenceRule") = DBNull.Value | |
| dr("RecurrenceParentID") = DBNull.Value | |
| '0 = " Instance type: 0-Single appointment<br>" | |
| '1 = " Instance type: 1-Master recurring appointment<br>" | |
| '2 = " Instance type: 2-Single instance, recurring appointment<br>" | |
| '3 = " Instance type: 3-Exception to a recurring appointment<br>" | |
| dt.Rows.Add(dr) | |
| Next | |
| End If | |
| End Sub | |
| Function SendRequest(ByVal strCommand As String, ByVal strURL As String, ByVal strBody As String, _ | |
| ByRef strStatusText As String, ByRef iStatCode As Integer) As XmlDocument | |
| Try | |
| ' Create a new CredentialCache object and fill it with the network credentials required to access the server. | |
| Dim Username As String = System.Configuration.ConfigurationManager.AppSettings("UserForReadingCalendars") | |
| Dim Password As String = System.Configuration.ConfigurationManager.AppSettings("PwdForReadingCalendars") | |
| Dim strDomain As String = System.Configuration.ConfigurationManager.AppSettings("WindowsDomain") | |
| Dim myCred As New NetworkCredential(strDomain & "\" & Username, Password) | |
| Dim myUri As System.Uri = New System.Uri(strURL) | |
| Dim MyCredentialCache As New CredentialCache | |
| MyCredentialCache.Add(myUri, "Basic", myCred) | |
| ' Create the HttpWebRequest object. | |
| Dim objRequest As HttpWebRequest = CType(WebRequest.Create(strURL), HttpWebRequest) | |
| ' Add the network credentials to the request. | |
| objRequest.Credentials = MyCredentialCache | |
| ' Specify the method. | |
| objRequest.Method = strCommand | |
| ' Set Headers | |
| objRequest.KeepAlive = True | |
| objRequest.Headers.Set("Pragma", "no-cache") | |
| objRequest.ContentType = "text/xml" | |
| 'Set the request timeout to 5 minutes | |
| objRequest.Timeout = 300000 | |
| If (strBody.Length > 0) Then | |
| ' Store the data in a byte array | |
| Dim ByteQuery() As Byte = System.Text.Encoding.ASCII.GetBytes(strBody) | |
| objRequest.ContentLength = ByteQuery.Length | |
| Dim QueryStream As Stream = objRequest.GetRequestStream() | |
| ' Write the data to be posted to the Request Stream | |
| QueryStream.Write(ByteQuery, 0, ByteQuery.Length) | |
| QueryStream.Close() | |
| End If | |
| ' Send the method request and get the response from the server. | |
| Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse) | |
| ' Get the Status code | |
| iStatCode = objResponse.StatusCode | |
| strStatusText = objResponse.StatusDescription | |
| ' Get the XML response stream. | |
| Dim ResponseStream As System.IO.Stream = objResponse.GetResponseStream() | |
| ' Create the XmlDocument object from the XML response stream. | |
| Dim ResponseXmlDoc As New System.Xml.XmlDocument | |
| ResponseXmlDoc.Load(ResponseStream) | |
| ' Clean up. | |
| ResponseStream.Close() | |
| objResponse.Close() | |
| Return ResponseXmlDoc | |
| Catch ex As Exception | |
| Throw ex | |
| End Try | |
| Return Nothing | |
| End Function | |
| End Class | |