예제 #1
0
        private void InitializeSPWebService()
        {
            spService = new SPListsService.Lists();
            spService.Credentials = new NetworkCredential("harley.admin", "ServeMe*99");
            spService.Url = "http://mws-wss0/sites/spdesign/testcalsite/_vti_bin/Lists.asmx";

            //find the calendar list
            XmlNode nodeListCollection = spService.GetListCollection();
            bool foundCalendar = false;

            foreach (XmlNode node in nodeListCollection.ChildNodes)
            {
                if (node.Attributes != null && node.Attributes["ServerTemplate"] != null)
                {
                    if (node.Attributes["ServerTemplate"].Value == "106" && !foundCalendar) //106 is Reserved List Template ID for "Events List" - ie: calendars (calendars are Events Lists rendered using the calendar "view")
                    {
                        calendarListGUID = node.Attributes["ID"].Value;
                        foundCalendar = true;
                    }
                }
            }
        }
예제 #2
0
        private void LoadTextBox()
        {
            SPListsService.Lists service = new SPListsService.Lists();
            service.Credentials = new NetworkCredential("harley.admin", "ServeMe*99");

            // OR include domain: service.Credentials = new NetworkCredential("harley.admin", "ServeMe*99", "ANANTA");
            // create username and pass for this app as a user in CORP's SP (Admin level? Read Only user?). Store/retreive them in/from the DB??

            //URL needs to be explicitly set for this instance of the Web Service, even though it's the same as
            //the URL property of the Project's Reference to the Web Service. 
            // Seems to be empty string other wise - still connects, but returns lists from SP DB for the "Web" with it's "FullUrl" field = "" (in the "Webs" table)
            service.Url = "http://mws-wss0/sites/spdesign/testcalsite/_vti_bin/Lists.asmx";

            XmlNode nodeListCollection = service.GetListCollection();
            string calendarListGUID = "";
            bool foundCalendar = false;

            foreach (XmlNode node in nodeListCollection.ChildNodes)
            {
                if (node.Attributes != null && node.Attributes["ServerTemplate"] != null)
                {
                    if (node.Attributes["ServerTemplate"].Value == "106" && !foundCalendar) //106 is Reserved List Template ID for "Events List" - ie: calendars (calendars are Events Lists rendered using the calendar "view"
                    {
                        calendarListGUID = node.Attributes["ID"].Value;
                        foundCalendar = true;
                    }
                }
            }

            //XmlNode nodeList;
            //if(calendarListGUID != "")
            //    nodeList = service.GetList(calendarListGUID);

            //nodeList = service.GetList("31ac8592-8907-492b-89a0-ddda159cec14");
            //txtTextBox1.Text = node.OuterXml;

            if (calendarListGUID != "")
            {
                XmlDocument xmlDoc = new XmlDocument();
                XmlNode nodeQuery;

                nodeQuery = xmlDoc.CreateElement("Query");
                nodeQuery.InnerXml = "<OrderBy><FieldRef Name='Location'></FieldRef><FieldRef Name='Title'></FieldRef></OrderBy>";

                XmlNode nodeFields;
                nodeFields = xmlDoc.CreateElement("ViewFields");
                //nodeFields.InnerXml = "<ViewFields/>";
                //nodeFields.InnerXml = "<FieldRef Name='Title'/><FieldRef Name='Location'/><FieldRef Name='EventDate'/><FieldRef Name='EndDate'/><FieldRef Name='Description'/><FieldRef Name='Recurrence'/>";

                XmlNode nodeCAML;
                nodeCAML = service.GetListItems(calendarListGUID, null, nodeQuery, nodeFields, null, null, "");

                StringBuilder output = new StringBuilder();

                // parse using Xpath - avoids looping through "whitespace" nodes that have no attributes
                // this selects all "element" type nodes only that are children of <rs:data ...> element. ie: the list items.
                // selecting "elements" means we can use .HasAttribute() instead of looping thru all attributes (there's a a lot of them that we don't want)
                foreach (XmlElement item in nodeCAML.ChildNodes[1].SelectNodes("child::*"))
                {
                    if (item.HasAttribute("ows_ID"))
                    {
                        output.Append(item.Attributes["ows_ID"].Value);
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_Title"))
                    {
                        output.Append(item.Attributes["ows_Title"].Value);
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_Location"))
                    {
                        output.Append(item.Attributes["ows_Location"].Value);
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_EventDate"))
                    {
                        DateTime eventDate = Convert.ToDateTime(item.Attributes["ows_EventDate"].Value);
                        output.Append(eventDate.Date.ToString("MMM dd/yyyy"));
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_EndDate"))
                    {
                        DateTime endDate = Convert.ToDateTime(item.Attributes["ows_EndDate"].Value);
                        output.Append(endDate.Date.ToString("MMM dd/yyyy"));
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_Description"))
                    {
                        string description = RemoveTags(item.Attributes["ows_Description"].Value);
                        if (description.Length > 15)
                            description = description.Substring(0, 15) + "...";

                        output.Append(description);
                        output.Append("  ");
                    }

                    if (item.HasAttribute("ows_fRecurrence"))
                    {
                        output.Append("RecurrenceField=" + item.Attributes["ows_fRecurrence"].Value);
                        output.Append("  ");
                    }

                    output.Append(Environment.NewLine);
                }

                // parse using loops 
                // must find only "element" type nodes that have attributes before accessing values
                /*foreach (XmlNode node in nodeCAML.ChildNodes[1].ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Element && node.Attributes != null)
                    {
                        foreach (XmlAttribute attribute in node.Attributes)
                        {
                            switch (attribute.Name)
                            {
                                case "ows_ID":
                                    output.Append(node.Attributes["ows_ID"].Value);
                                    output.Append("  ");
                                    break;
                                case "ows_Title":
                                    output.Append(node.Attributes["ows_Title"].Value);
                                    output.Append("  ");
                                    break;
                                case "ows_Location":
                                    output.Append(node.Attributes["ows_Location"].Value);
                                    output.Append("  ");
                                    break;
                                case "ows_EventDate":
                                    DateTime eventDate = Convert.ToDateTime(node.Attributes["ows_EventDate"].Value);
                                    output.Append(eventDate.Date.ToString("MMM dd/yyyy"));
                                    output.Append("  ");
                                    break;
                                case "ows_EndDate":
                                    DateTime endDate = Convert.ToDateTime(node.Attributes["ows_EndDate"].Value);
                                    output.Append(endDate.Date.ToString("MMM dd/yyyy"));
                                    output.Append("  ");
                                    break;
                                case "ows_Description":
                                    string description = RemoveTags(node.Attributes["ows_Description"].Value);
                                    if (description.Length > 15)
                                        description = description.Substring(0, 15) + "...";

                                    output.Append(description);
                                    output.Append("  ");
                                    break;

                            }
                        }

                        output.Append(Environment.NewLine);
                    }
                }*/

                txtTextBox1.Text = output.ToString() + Environment.NewLine + Environment.NewLine;

                foreach (XmlNode node in nodeCAML.ChildNodes)
                {
                    txtTextBox1.Text += node.OuterXml;
                }
            }
        }
예제 #3
0
        private void InitializeSPWebService()
        {
            string user = ConfigurationManager.AppSettings["SharepointUser"];
            string pass = ConfigurationManager.AppSettings["SharepointPass"];
            string serviceUrl = ConfigurationManager.AppSettings["SharepointServiceURL"];

            spService = new SPListsService.Lists();
            spService.Credentials = new NetworkCredential(user, pass);
            spService.Url = serviceUrl;

            //find the calendar list
            XmlNode nodeListCollection = spService.GetListCollection();
            bool foundCalendar = false;

            foreach (XmlNode node in nodeListCollection.ChildNodes)
            {
                if (node.Attributes != null && node.Attributes["ServerTemplate"] != null)
                {
                    if (node.Attributes["ServerTemplate"].Value == "106" && !foundCalendar) //106 is Reserved List Template ID for "Events List" - ie: calendars (calendars are Events Lists rendered using the calendar "view")
                    {
                        calendarListGUID = node.Attributes["ID"].Value;
                        foundCalendar = true;
                    }
                }
            }
        }