Monday, April 22, 2013

Using CSS Direct Descendant Selector with Tables

Recently I was attempting to use a  CSS 'direct descendant' selector (>) to set a bottom border on rows in a table. Because there were rows buried deeper in nested tables, I didn't want those to have the border. When I used the following CSS selector, it didn't work.

   table.employee > tr

Turns out, I needed to add a TBODY between the TABLE and TR, even though a TBODY was not showing in the page source because the TBODY is implictly added.


table.employee > tbody > tr
 
 

Thursday, April 4, 2013

Using Request.QueryString in Page_Load in SharePoint page layout


Below is an example of using the Request.QueryString collection in the Page_Load method in a SharePoint page layout. In this case we're looking for the variable named 'tab' and checking for various conditions.


try
{
  int index = System.Convert.ToInt32(Request.QueryString["tab"]);
  if (index > 1 && index < 5)
  {
    if (RadTabStrip1.Tabs[index-1].Visible)
    {
       RadTabStrip1.Tabs[index-1].Selected = true;
       RadMultiPage1.PageViews[index-1].Selected = true;
    }
  }
}
catch (Exception ex)
{
  //    Response.Write(ex.Message);
}

Thursday, March 28, 2013

Using word-wrap for an AspMenu SharePoint web control with long menu items

I have an AspMenu SharePoint web control with long menu items that do not respect the width of the table cell that I've set even though I have the property 'ItemWrap' set to 'True'. The biggest culprit is users wanting to use a series of  underscores to separate one group od links from another. To keep an extra long series of underscores from pushing the table cell wider, I'm using the stylesheet rule 'word-wrap' as shown below.

The ASPMenu control creates this hierarchy of tables. 

div#s4-leftpanel table tr td table
{
       table-layout:fixed;
}
div#s4-leftpanel table tr td table tr td
{
       word-wrap:break-word;
}

Monday, March 11, 2013

Hiding SharePoint list columns from NewForm.aspx using JavaScript

There are times I create a column in a SharePoint custom list and I don't want anyone with Contribute rights to alter the default value. In the NewForm.aspx and EditForm.aspx pages I add the following script to a CEWP on the page.

<script type="text/javascript">
  function HideField(title){
   var header_h3 = document.getElementsByTagName("h3");
   for (var i = 0; i < header_h3.length; i++)
   {
       var el = header_h3[i];
       var foundField;
       if (el.className=="ms-standardheader")
       {
           for (var j=0; j<el.childNodes.length; j++)
           {
              if (el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)
             {
                 var elRow = el.parentNode.parentNode;
                 elRow.style.display = "none"; //and hide the row
                 foundField = true;
                 break;
         }
      }       
    }
     if (foundField)
  break;
 }
}
HideField("Workspace");
HideField("Remote Item ID");
</script>

Thursday, February 21, 2013

Content Query Web Part using Custom ItemStyle.xsl


To set an existing Content Query Web part to use a custom ItemStyle.xsl file for custom styling list entries, we need to update the following property in the Content Query Web Part.webpart file after exporting to the Desktop.
<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/ItemStyleCustom.xsl</property>
After uploading back to the page, the web part now allows you to choose custom item templates in the ItemStyleCustom.xsl file you've created.

Friday, February 15, 2013

SPDataSource and the CrossList DataSourceMode


I was recently searching for how to construct an SPDataSource using a Crosslist or Union of two or more SharePoint lists. Not finding the answer in one place, I was able to piece together the answer. Because we're doing a union of lists, the column names and type in each list must match.


<SharePointWebControls:SPDataSource
runat="server"
ID="spDataSource1"
DataSourceMode="CrossList"
SelectCommand="<Webs Scope='SiteCollection'></Webs>
  <Lists>
    <List ID='XXXXXXXX-XXXX-4499-91F3-359A463EB89F'></List>
    <List ID='XXXXXXXX-XXXX-4EBE-9801-8751A076F069'></List>
  </Lists>
  <View>
    <ViewFields><FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /></ViewFields>
    <Query>
      <Where><Geq><FieldRef Name='EndDate'/><Value  Type='DateTime'><Today/></Value></Geq>
      </Where>
      <OrderBy><FieldRef Name='EventDate' Ascending='True'/></OrderBy>
    </Query>
    <RowLimit>5</RowLimit>
  </View>"

</SharePointWebControls:SPDataSource>

Friday, December 7, 2012

Getting List Items from a SharePoint List using SOAP

Use the steps below to get list items from a SharePoint list using SOAP.

First construct your xml SOAP message:


StringBuilder sbEnvelope = new StringBuilder();
sbEnvelope.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sbEnvelope.Append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");

sbEnvelope.Append("<soap:Body><GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<listName>" + listname + "</listName><viewName>" + viewName + "</viewName>" +
 "<query></query><viewFields><ViewFields><FieldRef Name='Column1' /><FieldRef Name='Column2' /><FieldRef Name='Column3' /></ViewFields></viewFields></GetListItems></soap:Body></soap:Envelope>");

Next, construct your HttpWebRequest, get your response and place it in an XmlDocument for parsing.


HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://<site>/_vti_bin/lists.asmx");
req.Method = "POST";
req.ContentType = "text/xml; charset=\"utf-8\"";
req.Accept = "text/xml";
req.Headers.Add("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
req.UseDefaultCredentials = true;

using (Stream stream = req.GetRequestStream()) 
{
      using (StreamWriter writer1 = new StreamWriter(stream)) 
     {
            writer1.Write(sbEnvelope.ToString());
      }
}

WebResponse response = req.GetResponse();
Stream responseStream = response.GetResponseStream();

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(responseStream);

Finally, create your namespaces and parse the xml.


XmlNamespaceManager manager = new XmlNamespaceManager(xmlDocument.NameTable);
manager.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
manager.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
manager.AddNamespace("z", "#RowsetSchema");
manager.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
manager.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
manager.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");

XmlNodeList NodeList = xmlDocument.SelectNodes("//sp:listitems/rs:data", manager);

String t = "";
foreach (XmlNode ListItem in NodeList)
{
     foreach (XmlNode node in ListItem.ChildNodes)
    {
         t = node.Attributes["ows_Title"].Value;
     }
}