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;
     }
}


Tuesday, December 4, 2012

All (%) in Crystal Reports Formula Editor

When constructing a parameter in Crystal Reports that includes "all" items (%), construct a formula that returns true or false for your report's selection criteria.

In the formula editor, add:


//Selects all academic orgs or specific ones based on parameter
if {?Academic Orgs}="%" then  true
else
     if {?Academic Orgs} = {RDS_CLASS_TBL.CLASS_ACAD_ORG} then true
else
     false

Then for your record selection include your formula:

... and{@Selection Criteria for Academic Orgs} ...

Tuesday, November 27, 2012

Show attachment from Remedy in .NET web app

We have a BMC Remedy form that contains classroom information along with jpg or gif attachments. To pull these images from the Remedy form into a .NET web application, use the following code:


            byte[] content = null;
            server.GetEntryBLOB("AssetRooms", id, 536880917, out content);
           
            string base64String = Convert.ToBase64String(content, 0, content.Length);

            if (base64String.Equals(""))
            {
                Label1.Text = "<br/><br/> Map not available.";
                Image1.Visible = false;
            }
            else
            {
                Image1.ImageUrl = "data:image/png;base64," + base64String;
                Image1.Visible = true;
            }

Image1 is an Image control:

<asp:Image ID="Image1" runat="server" Height = "380"/>

Friday, November 16, 2012

XSL for SharePoint List webparts

For out-of-the-box SharePoint List webparts, the 'XSL Link' property allows editors to customize the display of their list data.

Below is an example of an xsl stylesheet for list webparts.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="msxsl"
  xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="yes"/>

<xsl:template match="dsQueryResponse" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
  <div class="resourcesList" >
      <xsl:apply-templates select="/dsQueryResponse/Rows/Row"/>
  </div> 
</xsl:template>

<xsl:template match="Row">
    <xsl:if test="position()=1">
    <h2><xsl:value-of select="@Category" disable-output-escaping="yes" /></h2>
    </xsl:if>
    <a href="{substring-before(substring-after(@URL,'&gt;'),'&lt;')}">
     <xsl:value-of select="@Title" disable-output-escaping="yes" />
    </a> <br/>
</xsl:template>

</xsl:stylesheet>

Using XSLT gives a much cleaner and customized look to your list webparts.


Friday, November 9, 2012

Launch your web browser as a different user

I often need to sign into SharePoint or another local server as a different user. An easy way to do this without logging out of your computer is to use the 'runas.exe' command. open a command prompt and enter the following command:

runas.exe /u:domain\username "C:\Program Files\Internet Explorer\iexplore.exe"

substitute domain\username with your account you want to login in with, I use a test account made specifically for these situations.

Monday, November 5, 2012

RANK function to create primary key for a Remedy View Form

To create Remedy View Form, you will need a database table or view that contains a numeric primary key. Since your table or view might not have a column that fits this requirement, you may need to dynamicall y create one in the building of the view.

Use the RANK function to create an incrementing value and then cast it as a an integer:

CAST(RANK() OVER(ORDER BY TERM,CAMPUS,BUILDING,ROOM,CRS_PREFIX,CRS_NUMBER,CRS_SUFFIX) AS int) AS Record

Thursday, October 18, 2012

AttachmentField control in SharePoint


The SharePoint AttachmentsField is used to display attachments from an SP list item.

<td align="center" id="att_{@ID}">
<xsl:if test="@Attachments='1'">
<SharePoint:AttachmentsField ID="att{@ID}" ControlMode="Display" ListId="{$ListID}" ItemId="{@ID}" FieldName="Attachments" visible="true" runat="server" />
</xsl:if>
</td>

The HTML that is rendered includes a table with a row for each attachment. The anchor tag look something like:

<a href="/student-affairs/athletics/athletics-w/basketball/Lists/Schedule/Attachments/11/statistics.html">20090312.6.html</a>

Mod operator to control Table Rows in XSL


The Mod operator returns the remainder left after division is performed. If you have a table and you need to have a certain amounts of columns before another row is created, use the mod operator.

The following example will create a new row after 3 columns are created.

<xsl:if test="position() mod 3 = 1">
<xsl:text disable-output-escaping="yes"><![CDATA[ <tr> ]]></xsl:text>
</xsl:if>
   <td valign="top">
    <img alt="" src="{@ImgURL}"/>
    <xsl:call-template name="dvt_2" />
   </td>
<xsl:if test="position() mod 3 = 3">
<xsl:text disable-output-escaping="yes"><![CDATA[ </tr> ]]></xsl:text>
</xsl:if>

Monday, September 24, 2012

Customizing the Summary Links with custom itemStyles.xslt


The Summary Links control (PublishingWebControls:summarylinkfieldcontrol) allows you to specify your own styles using the ItemXslLink property as shown below. 

<PublishingWebControls:summarylinkfieldcontrol ItemXslLink="/Style Library/XSL Style Sheets/InsideHomeItemStyle.xsl" .../>

In SP Designer, you can copy an existing xsl file and rename it, you can then update the file with your own styles and template names.

As a demo of how this works, the following New Home page layout has two Summary Link areas.


The custom itemStyles.xsl file I created has only 2 styles to chose from; insideHome1 & insideHome2. Both styles include a bullet icon in front of the link but insideHome1 colors the link teal, insideHome2 colors the link orange.

If you have a Links Webpart that you've added to a zone in your publishing page, you can export the webpart and modify the webpart file with the following xml:


<property name="HeaderXslLink" type="string">/Style Library/XSL Style Sheets/CustomHeader.xsl</property>
<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/CustomItemStyle.xsl</property>

Save, add and upload your webpart. Your new header and styles will now be available.

Tuesday, September 18, 2012

Using the Previous function to supress Detail rows


When your query in Crystal does not return Distinct records, you may want to supress rows in the Details section based upon the previous value of a field or fields. Add the following code to the Supress code area in the Section Expert for the Details section:

 
if (not onfirstrecord) then
    previous({RDS_CLASS_VW.CLASS_CLASS_NBR})={RDS_CLASS_VW.CLASS_CLASS_NBR}

Wednesday, September 12, 2012

Using the IN Operator in a CAML Query

The In operator is used in an SQL query allows you to specify multiple values in a
WHERE clause. The CAML query language also uses the IN operator, in place of using multiple ORs, to return multiple values of a column.

<In><FieldRef Name='Col1'/>
    <Values>
        <Value Type='Text'>A</Value>
        <Value Type='Text'>B</Value>
        <Value Type='Text'>C</Value>
    </Values>
</In>

Monday, July 30, 2012

Using PowerShell to downgrade a SharePoint v4 site to v3


Use the following powershell commands on a SharePoint front end server to downgrade a v4 site to v3.

$Web=Get-SPWeb http://<site name>/<site>
$Web.UIVersion=3
$Web.UIVersionConfigurationEnabled=$true
$Web.update()

Wednesday, July 18, 2012

Using the Eval method in a SharePoint master or layout page

Examples of using Eval method in SharePoint master or layout page:


In this example "Include Time" is a SP yes/no field where we're checking for a value of "yes":



<%# Eval("Include Time").ToString() == "True" ? " (" + Eval("Start Time","{0:hh:mm tt}") + ")" : "" %>



In this example "Active" is a SP yes/no field where it's casted to a boolean value and then used to control visibility of an asp:Label control:



Visible='<%# bool.Parse(Eval("Active").ToString()) %>'

Another example of setting the Visible property. If the value of Descrition is null, hide the control:

Visible='<%# bool.Parse(Eval("Description") == null ? "False" : "True") %>'

Tuesday, July 10, 2012

SubjectsAll dynamic prompt for Crystal


The prompt group 'RDS SubjAll M' in Crystal Reports requires logic in the Record Selection formula to account for the ' All' value for all subjects. Below is an example of how to construct the query:

if ({?Subject} <> " All") then 
({?Subject} = {RDS_CLASS_VW.CLASS_SUBJECT_CD} and
{?Institution} = {RDS_CLASS_VW.CLASS_INSTITUTION_CD})
else
{?Institution} = {RDS_CLASS_VW.CLASS_INSTITUTION_CD}

If the Subject parameter equals ' All' we simply ignore it.

Monday, July 9, 2012

Removing annoying checkboxes in a List web part

When I add a List web part to a page, I'm left with a bunch of annoying check boxes in front of each item, as shown below:










To get rid of these, since they don't really serve any purpose on our public pages, I've added a content editor web part to the page with the following css code. Make sure you add the code using the source editor:

<style type="text/css">
TH.ms-vh-icon {
DISPLAY: none
}
.ms-vb-itmcbx {
DISPLAY: none
}
</style>

I then get a cleaner look to the listing with the check boxes removed from the page.

Tuesday, May 22, 2012

Adding Javascript to a SharePoint Master or Layout page

If you need to add javascript to a SharePoint Master or Layout page, add the script to the Head section or PlaceHolderAdditionalHead content area. Be sure to include the  _spBodyOnLoadFunctionNames.push function so your function is added to the OnLoad method.

<script type="text/javascript">
function UpdateCampusAddress()
{
if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Williams Campus";
}
else if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Sun Lakes Campus";
}
}
_spBodyOnLoadFunctionNames.push("UpdateCampusAddress");
</script>

Tuesday, May 15, 2012

Empty dataset template for DataList control

There is no Empty dataset Template for the DataList control. To display a message in the DataList control if your dataset is empty, define a HeaderTemplate and set the visibility based upon the item count as shown below:
 
<asp:DataList runat="server" id="DataList1" DataSourceID="spDataSource1">
<HeaderTemplate>
<span style="font-style:italic;color:#181818">
<asp:Label ID="lblEmpty" Text="No Events" runat="server" Visible='<%# DataList1.Items.Count==0 %>'/>
</span>
</HeaderTemplate>
<ItemTemplate>
<p>
...
</p>
</ItemTemplate>
</asp:DataList>

Saturday, April 21, 2012

Breadcrumb added to SharePoint Masterpage

The publishing masterpage for the new website design now includes a readcrumb trail leading back to the Home site. The text in the breadcrumbs shows the Site titles as well as the current page title.

<asp:SiteMapPath ID="SiteMapPath" runat="server" CssClass="cgcc-breadcrumb" RenderCurrentNodeAsLink="true" skiplinktext="skip breadcrumb"/>
CGCC-v4.css is where the style is set so it's easy to change the color or font.

.cgcc-breadcrumb span a
{
color:#404040;
text-decoration:none;
}

Friday, April 20, 2012

Controlling SharePoint's Global Navigation

Lesley and I were talking about how we as members of the WebCS Owners
group can keep full control of the Global Navigation menu on the new design, thus preventing editors from changing the global nav in their site. Editors will need to
have access to the Site navigation so it isn't a matter of restricting their permissions. The way we set this up in the current site is to use a custom list to hold the global navigation entries.

There is a way to specify the Home site's global navigation instead of the current site's global navigation. By using the 2 properties below we are telling the menu to only use the Home site's global navigation when populating the menu for all sites.

<PublishingNavigation:PortalSiteMapDataSource
...
StartFromCurrentNode="false"
StartingNodeUrl="/"
.../>

What this means is editors can make changes to their site's global navigation settings without affecting what is displayed on the pages. Webmasters can make a change to the global navigation entries in the Home site and it will affect all sites regardless of whether or not the sub-sites are inheriting.

Tuesday, March 13, 2012

Comparing Publishing Dates of Blog Posts

When displaying the list of published posts from a SharePoint Blog, you may want to hide certain elements such as the Publish Date div box if there are multiple posts on the same day. The XSL code below will compare the publish date of the post to the previous post and display or not display the div accordingly.

<xsl:variable name="PrevPosition" select="count(./preceding-sibling::*)" />
<xsl:if test="($Rows/Row[$PrevPosition]/@PublishedDate.MonthDayOnly !=
$thisNode/@PublishedDate.MonthDayOnly) or ($PrevPosition+1 = $FirstRow)">
...
</xsl:if>

Tuesday, February 7, 2012

Changing the SP Ribbon background color using CSS

To change the background color of SharePoint's ribbon, override the following styles from the corev4.css file.


.ms-SpLinkButtonActive
{
background-color:orange !important;
}

.ms-welcomeMenu a:hover
{
background-color: orange !important;
}


.ms-siteactionsmenu .ms-siteactionsmenuhover
{
background-color: orange !important;
color:#000000 !important;
}


.ms-cui-ribbonTopBars
{
background: orange url() repeat-x !important;
padding-top:0px;
}