Wednesday, December 7, 2011

InfoPath 2007: After a Submit, make the view Read Only

I had what seemed like a pretty straightforward request:  "After the user submits the form, we'd like the form to be Read Only from then on".  Easy enough.

So I quickly added a new rule to switch views before submitting, but every time I'd open it up after it would revert to the "Editable" view, which happened to be the default view.

So if you just spin it and make your Read Only view the Default view, you can then go to Tools -> Form Options, "Open and Save" and add a new rule that keys off of something like an empty required field and switch the view to "Editable". 

From then on whenever that form is opened it will remain in the Read Only view.




Wednesday, October 26, 2011

Show Attachment File Names in a List View

Saw a cool way to modify a list view to show the attachment filenames.  Original post is from Alex Dean here and I wanted to expand upon it:

1) Open the site up in SharePoint Designer, click on the list where you'd like to add the column with filenames, and pick the view that you'd like to edit (e.g. AllItems.aspx)

2) Right click on the area displaying the view and select "Convert to XSLT Data View"

3) Then view the new web part, and search for the header row (it begins with):

                <!--Attachments--><TH nowrap="" scope="col" class="ms-vh-icon">

after the </TH>, add the following:

              <TH nowrap="" scope="col" class="ms-vh2">File Names</TH>

4) Scroll down a bit until you hit the rows:

            <!--Attachments-->
            <TD Class="{$IDAKFYXG}">
                <xsl:if test="not (@Attachments=0)"><img border="0" src="{$HttpVDir}/_layouts/images/attach.gif" /></xsl:if>
            </TD>

and add the following afterwards:

            <td>
                <SharePoint:AttachmentsField
                    ControlMode="Display"
                    ItemId="{@ID}"
                    FieldName="Attachments"
                    runat="server"/>
            </td>

Press save and you should see the filenames show up in your List View!

Tuesday, August 16, 2011

Web Part Report: Third Party Web Parts showing as "ErrorWebPart"

I found this great post to loop through our sites and get a list of web parts:

http://www.glynblogs.com/2011/07/listing-all-web-parts-in-a-site-collection-with-powershell.html

Though when I viewed the report, I noticed that many of our Bamboo web parts (e.g. particular AlertPlus and SPGridView and others) were showing up as "Microsoft.SharePoint.WebPartPages.ErrorWebPart".

Turns out that though there are many related assemblies in the GAC, the actual web part assemblies are not in the GAC. So just do a search for the DLLs you'd like, (In my case I dragged the Bamboo.AlertPlus.dll from the C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin to the GAC), closed and reopened PowerShell, re-ran the above script and was on my way with a useful report!

-Sean

Wednesday, July 13, 2011

Setting the ItemStyle for a ContentByQueryWebPart programmatically

If you're using the API to create a Content Query Web Part, if setting the styles, the ItemStyle is a string and can accept the following, which are the xsl:template names in the ItemStyle.xsl file in 14\TEMPLATE\Features\PublishingResources.

Item StyleUI Equivalent
DefaultImage on left
NoImageNo Image
TitleOnlyTitle Only
TitleWithBackgroundTitle With Background
BulletsBulleted title
ImageRightImage on right
ImageTopImage on top
ImageTopCenteredImage on top, centered
LargeTitleLarge title
ClickableImageImage only, clickable
NotClickableImageImage only, not clickable
FixedImageSizeFixed image size
WithDocIconTitle, description and document icon

Wednesday, June 29, 2011

SharePoint 2010 Search: Filter by Enterprise Keywords/Managed Metadata

I was looking at ways to filter SharePoint Search by the Enterprise Keywords that users are entering. On the search results page, you have the refinements right there on the left hand side, and if you inspect the url you see:

/Search/Pages/Results.aspx?k=test&r=owstaxIdMetadataAllTagsInfo%3D%2306a328dfa-d7c8-4ae1-bc35-e33936dc6807%3A"MyTag"

That's mildly helpful, but I can't tell users that they have to look up a GUID if they want a link that filters by a tag.

So what I wound up doing is creating a new Metadata Property in the Search Service Application, and then mapping it to the Crawled Property: ows_TaxKeyword

Now, when users want to do a search filter by a tag, they can just enter the following:

/Search/Pages/Results.aspx?k=MyNewMetadataProperty:'MyTag'

Friday, June 3, 2011

"Trying to use an SPWeb object that has been closed or disposed and is no longer valid."

I was getting the following error when my code was adding a web part to a SharePoint page:

Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

After reading this article:

http://insidesharepoint.blogspot.com/2007/07/trying-to-use-closeddisposed-webpart.html

I inspected my code and went from using this using (sorry had to write it like that):

using (SPSite spSite = SPContext.Current.Site)

and realized that I might be disposing the very site object that I'd need later on. So I changed it to this:

using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))

and it now works nicely!

Thursday, April 28, 2011

Deleting a SharePoint List that errors with Invalid Filename

Ever get in a situation where you create an instance of a list from a list definition, then remove that list definition, and then you're hard pressed to delete it: You can't via the UI, Manage Content and Structure throws an error, and it doesn't show in SharePoint Designer?

Well you can delete it using using PowerShell with an assist from SharePoint Manager:

1) Open SharePoint Manager, go to the list you want to delete, and copy the ID of it.
2) In PowerShell, run the following:

$web = Get-SPWeb "http://dev.yoursite.com"
$lc = $web.Lists
$lc.Delete("YOURGUID")

and then it'll be removed.

Tuesday, April 26, 2011

Adding JavaScript into RichHtmlField on Publishing Sites

To try and prevent scripting attacks, the RichHtmlField will remove any JavaScript code out when saving/checking in/publishing a page, and sadly there's no option to make it allow script tags. To get around this, I've used two alternatives in the past:

1) Add a Content Editor Web Part to your page, which will not strip JavaScript
2) Use the Telerik RadEditor

Any other alternatives are welcome!

"Save as Site Template" functionality for Publishing Sites via PowerShell

I came across a situation where I wanted to create a whole bunch of publishing sites, using one site as a template. Knowing that OOB, the "Save as Site Template" functionality is disabled (well kinda, you can always go straight to the url: /_layouts/savetmpl.aspx and give that a shot), I came up with an alternative using PowerShell.

What it's basically doing is exporting a site, creating a new site and then importing over the new site. The code is below:

# This creates sites based on the template provided.

function CreateWeb([string]$path, [string]$url, [string]$name)
{
Write-Host "Url: $url"
Write-Host "Path: $path"
Write-Host "Name: $name"

# Import the web that we saved
New-SPWeb -Url $url -Template "CMSPUBLISHING#0" -Name $name
Import-SPWeb -Identity $url -Path $path
$web = Get-SPWeb -Identity $url
$web.Title = $name
$web.Update()

# Change the Title of the page and publish it.
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web))
{
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pubWeb.PagesList
foreach($item in $pages.Items)
{
$pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)

$pubPage.CheckOut()
$pubPage.Title = $name
$pubPage.Update();
$pubPage.CheckIn("")
$pageFile = $pubPage.ListItem.File;
$pageFile.Publish("");
#$pageFile.Approve("");

}
}

$web.Dispose()

}

$path = "C:\Development\yourexportedweb.cmp"

# Create webs
CreateWeb $path "http://server/industries/financial" "Financial Services"
CreateWeb $path "http://server/industries/healthcare" "Healthcare"
CreateWeb $path "http://server/industries/insurance" "Insurance"

This is great for developers and admins, but not so much for end users, which is where the real need is. That'll have to be the next step...

Wednesday, April 20, 2011

Web Analytics Reports error with Custom Master Page

If you're using a custom master page and get an exception when trying to access the Web Analytics Reports that looks like this:
System.ArgumentException: Could not find the sitemap node with URL '/_layouts/WebAnalytics/WebAppSelection.aspx'. 
 The error is getting thrown from the PlaceHolderHorizontalNav, and if you clear it's contents inside you'll resolve the error:

              <asp:ContentPlaceHolder id="PlaceHolderHorizontalNav" runat="server">
                    <!-- Remove this to fix Web Analytics Report exception
                    <SharePoint:AspMenu
                          ID="TopNavigationMenuV4"
                          Runat="server"
                          EnableViewState="false"
                          DataSourceID="topSiteMap"
                          AccessKey="<%$Resources:wss,navigation_accesskey%>"
                          UseSimpleRendering="true"
                          UseSeparateCss="false"
                          Orientation="Horizontal"
                          StaticDisplayLevels="2"
                          MaximumDynamicDisplayLevels="1"
                          SkipLinkText=""
                          CssClass="s4-tn"/>
                        <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
                            <Template_Controls>
                                <asp:SiteMapDataSource
                                  ShowStartingNode="False"
                                  SiteMapProvider="SPNavigationProvider"
                                  id="topSiteMap"
                                  runat="server"
                                  StartingNodeUrl="sid:1002"/>
                            </Template_Controls>
                        </SharePoint:DelegateControl>
                       -->
                </asp:ContentPlaceHolder><sharepoint:aspmenu >

Sunday, April 3, 2011

Programatically Setting Column Default Value for Managed Metadata Column

I've been working on setting up document libraries with different column default values for managed metadata based on what site the library is in.  I achieved this with the following:  
  
        using (SPSite siteCollection = new SPSite("http://www.yoursite.com"))
        {
            using (SPWeb web = siteCollection.OpenWeb("/yourweb/"))
            {
                SPList customDocumentLibrary = web.Lists["Documents"];
                SPFolder rootFolder = customDocumentLibrary.RootFolder;

                MetadataDefaults columnDefaults = new MetadataDefaults(customDocumentLibrary);

                columnDefaults.RemoveAllDefaults();
                columnDefaults.SetFieldDefault(rootFolder, "Programs", "1033;#Academics|bc943091-79ac-4f5f-a79b-205e8e717823");
                columnDefaults.Update();
            }
        }

Note that if you don't add the proper value in the correct format you'll get the following error message:
 
The given value for a taxonomy field was not formatted in the required <int>;#
 
Where int is the lcid, label is the Term Name, and the Guid is the Term Guid.

Tuesday, February 15, 2011

Add Publishing Navigation in a Team Site

I had the need for a team site, but instead of the standard quick launch, I wanted more of a publishing like navigation setup.  So I did the following:

1)  Create a new Site Template.  For reference I used:

http://www.toddbaginski.com/blog/archive/2009/11/02/how-to-create-a-custom-site-definition-in-sharepoint-2010.aspx.aspx

I copied the STS site template onet.xml file, and then created a new template in my webtemp_custom.xml file.

2)  Next add the Navigation Feature under WebFeatures in your onet.xml file:

        <!-- NavigationProperties Feature-->
        <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="InheritGlobalNavigation" Value="true"/>
            <Property Key="ShowSiblings" Value="true"/>
            <Property Key="IncludeSubSites" Value="true"/>
          </Properties>
        </Feature> 

When you create a new site, you'll see that you have Navigation link in your Site Settings that you can now configure, just like a Publishing Site!

Failed to instantiate file "default.master" from module "DefaultMasterPage"

I ran into this error while trying to create a new Site Definition in SharePoint 2010.  It turns out that the TemplateName you select in your webtemp_custom.xml file:

<Template Name="CustonSiteDefinitions" ID="10000">

Must match the folder in your SiteTemplates directory:

14/TEMPLATE/SiteTemplates/CustomSiteDefinitions

otherwise you'll get the error above.

Thursday, February 10, 2011

Stsadm upgradesolution vs. deploysolution

upgradesolution != deploysolution

There are certain times when you can use upgradesolution, primarily only when you haven't added or removed any files from the project. 

The list of the constraints for when you cannot use stsadm –o upgradesolution:
  • The following operations are not supported in solution upgrade.
  • Removing old Features in a new version of a solution.
  • Adding new Features in a solution upgrade.
  • Updating or changing the receiver assembly for existing Features in a new version of a solution.
  • Adding or changing Feature elements (Element.xml files) in a new version of a solution.
  • Adding or changing Feature properties in a new version of a solution.
  • Changing the ID or scope of old Features in a new version of a solution.
  • Removing Feature elements (Element.xml files) in a new version of a solution.
  • Removing Feature properties in a new version of a solution. 
So if any of the above cases apply to you, you should do a retract/delete/add/deploy solution.

Friday, January 21, 2011

Changing the Application Master Page

Some system files (for example EditProfile.aspx in My sites) have a hard coded url to the application.master page:

MasterPageFile="~/_layouts/application.master"

If you'd like to use your own master page, you'd have to change this to the following:

DynamicMasterPageFile="~masterurl/default.master"

And FYI changing these system files is technically unsupported, but I've often found it's sometimes a necessity.