none
Print out HTML from aspx.cs to aspx page

    问题

  • I am trying to print out the following announcement Titles on my aspx web page that i retrieved from a sharepoint site that i put in the aspx.cs file.  How do i go about printing this information out directly on the aspx page from the aspx.cs file?  

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.SharePoint.Client;
    using SP = Microsoft.SharePoint.Client;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string siteUrl = "http://win-l1l6hbqrvsh";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;
            clientContext.Load(site);
            clientContext.ExecuteQuery();
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
            CamlQuery camlQuery = new CamlQuery();

            camlQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query></View>";
            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in collListItem)
            {
                Response.Write("<li> Title: " + oListItem["Title"] + "</li>");
            }
        }
    }

    2012年6月28日 0:25

答案