Skip to content

Instantly share code, notes, and snippets.

@reallyseth
reallyseth / SPLookupFieldNoLink.xml
Created July 8, 2011 21:51
SharePoint 2010 Lookup Field without Link
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using System.Xml.XPath;
using System.Web.UI.WebControls.WebParts;
namespace MySharePoint.Features
<ElementManifests>
<!-- Configurations -->
<ElementFile Location="configuration.xml"/>
<!-- WebParts -->
<ElementFile Location="Example.webpart" />
</ElementManifests>
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<Page FileName="pages/default.aspx">
<WebPart Id="00000000-0000-0000-0000-000000000000" ZoneId="Left" Index="1" FileName="Example.webpart" Type="Definition" />
<WebPart Id="00000000-0000-0000-0000-000000000000" ZoneId="Right" Index="1" FileName="" Type="ListView" ListName="Announcements" />
</Page>
<Page FileName="pages/AnotherPage.aspx">
<WebPart Id="00000000-0000-0000-0000-000000000000" ZoneId="Main" Index="1" FileName="Example.webpart" Type="Definition" />
</Page>
</Configuration>
try
{
// Get the limitedWebPartManager of the page layout file.
using (SPLimitedWebPartManager wpManager = page.File.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
// cycle through each web part and get the different attributes
foreach (XPathNavigator webPartConfiguration in pageLayoutConfiguration.Select("WebPart"))
{
string errorMsg = null;
string webPartFilename = webPartConfiguration.GetAttribute("FileName", "");