Skip to main content
 
Go Search
Home
Categories
Bloggers
By: Bob Moore | Posted: April 2, 2010 at 9:51 PM

Wouldn’t it be nice in SharePoint 2007 if we could put our own buttons into the publishing menu?  We can...it just takes a few steps.  The steps taken are determined by the master page that is used.  If you are using default.master, you will need to create a delegate control.  There are plenty of examples for adding your own delegate control, so I will not go into that.  My delegate control was copied from the PublishingMenu.ascx.  The control we want to change within the publishing console is called the QuickAccessMenu.  I wanted to start a custom workflow that was part of an approval process and I wanted users to enter comments when the workflow was started.  I created my own check in page that the button redirects the users to when it is clicked.  My check in page requires comments and starts a workflow.  To do this I created my own QuickAccessMenu control that instantiates the MS QuickAccessMenu.  I then use the following code to change the functionality of the Submit for Review button:

 

public override void RenderControl(HtmlTextWriter writer)

{

  int location = GetControlLocation();

  if (location > 0)

  {

    Control pub = menu.FindControl("qaApprovePublish");

    if (pub != null && !SPContext.Current.Web.CurrentUser.IsSiteAdmin)

      pub.Visible = false;

 

    Control ctrl = (Control)menu.Controls[location];

    PublishingButton button = (PublishingButton)ctrl.Controls[0];

    button.DisplayText = "Start Custom Workflow";

    string url = string.Format("{2}/_layouts/CustomLayouts/CustomCheckin.aspx?List={0}&FileName={1}&Publish=true&Source={1}&ListItemID={3}",         SPContext.Current.ListItem.ParentList.ID.ToString("B"), SPContext.Current.Item["FileRef"].ToString(), SPContext.Current.Web.Url, SPContext.Current.ListItem.ID);

    button.ClientOnClickScript = string.Format("location.href='{0}'", url);

   }

           

  base.RenderControl(writer);

}

 

The code above searched for a control called “qaPublish” and changes the some properties on the button before rendering.  When the control is rendered it looks like the following image:

You can add new buttons to the control as well.  The button type is PublishingButton.  This will allow you to start workflows from these buttons or anything else you want.

By: Bob Moore | Posted: March 15, 2010 at 10:31 PM

I recently had a client requirement to associate documents and pages within SharePoint to specific pages.  The client wanted to associate the documents / pages through metadata.  After thinking about this for a while I remembered the lookup with picker control on CodePlex.  The picker control on CodePlex was designed to work with lookup fields and I wasn’t prepared to have a metadata field for each pages library or document library in the system.  I decided to change the lookup with picker to perform a site query be content type and show the results title and file reference.  To do this I had one obstacle to overcome…what kind of field should this be?  The easiest way was to make it a note field and require the users edit the field on the page.  In this post I will explain what I had to change in the picker to get this to work.

LookupWithPickerField

A custom field control was required for displaying the field control on the page layout.  The field control resembles a picker field.  While in edit mode the users would see the following:

Page Field

The field displays the selected item along with the icon to open the picker.  I removed the icon to validate typed in items and also disabled the ability to type in the item.  The custom field also contains the following properties:

·         ContentTypeName – This property is used by the picker dialog for the site query

·         IsDocLib – Since the site query needs the type of library to search I need to know if it is a pages library or document library

·         AllowMultipleValues – Allows for multi select in the picker dialog

CustomLookupEntityEditor

This class is the control that is rendered in the picture above.  The class extends the EntityEditorWithPicker class.  The code for this class overrides the init method and sets the PickerDialogType, AllowTypeIn, and the CheckButtonImageName.  AllowTypeIn is set to false since I do not want users to manually type in the field and the CheckButtonImageName is set to blank.gif because I do not want to show the button.

CustomLookupPickerDialog

The next class I changed was the CustomLookupPickerDialog.  I added the fields I wanted to display in the dialog along with the column widths for each field.  In this case I am displaying Title and FileRef.

CustomLookupQueryControl

The CustomLookupQueryControl is the class that is doing all of the heavy lifting.  This class takes the content type name supplied on the LookupWithPickerField properties and uses it to query the entire site.  When a user clicks the book icon that is displayed in the field control the results will appear like the following image:

Popup

A user can then select the item(s) they are looking for.  If there is a lot of data the search results can be narrowed by typing text in the box at the top and clicking the search button.  The two fields that are displayed in the picker are the fields that are saved in the note field as part of the metadata.  

By: Bob Moore | Posted: February 12, 2010 at 11:09 PM
I was recently trying to restore an environment at a client site and kept getting access is denied.  This baffled me because the account I was using had the proper database permissions to perform the task at hand and is a local admin on the server.  The user is the account that I was used to create the web application.
 
It turns out the the user performing the restore needs to be a site collection administrator to restore from a backup.  So in review the user account must have the proper rights (in my case they were dbo on the database) and be a site collection administrator on the site that you are trying to overwrite.
By: Bob Moore | Posted: December 30, 2009 at 2:13 PM
I decided to expand on one of Travis Neilson's posts called Introducing Documents Sets.  Being the eternal developer that I am I decided to write a blog on how to create a Document Set using C# and the new object model for SP2010. 
 
In trying to figure out how to do this, I though I would try the 2007 way and add a new ListItem to my test document library....well that didn't work so well.  While I was looking at the code for the NewDocSet.aspx page I stumbled upon a new assembly and namespace.  The assembly that I am referring to is Microsoft.Office.DocumentManagement and the namespace is Microsoft.Office.DocumentManagement.DocumentSets.  Within the new namespace lives the DocumentSet class.  The DocumentSet class is makes it pretty easy for creating a DocumentSet.  Using the same content types from Travis' blog I created a quick console application to create the DocumentSet in code.  Below are the lines of code necessary to create a DocumentSet using the default content:

SPSite site = new SPSite("http://sp2010");

SPWeb web = site.OpenWeb();

SPList list = web.Lists["Proposals"];

Hashtable props = new Hashtable();

props.Add("Name", "Proposal 1");

props.Add("Description", "Proposal 1");

props.Add("Customer ID", "1234");

props.Add("Customer Name", "Customer 1");

DocumentSet ds = DocumentSet.Create(list.RootFolder, "Proposal 2", list.ContentTypes["Proposals"].Id, props, true);

web.Dispose();

site.Dispose();

If you do not want to provision default content then after you create the DocumentSet you can add the desired content by manipulating the Item property (SPListItem) of the DocumentSet.
By: Bob Moore | Posted: December 30, 2009 at 1:58 PM
After being shown the Managed Metadata Service and the Term Stores in SharePoint 2010, I felt the need to figure out how to create all of the items that were shown to me in code.  Below is a list of new classes that we will be using to accomplish the task:
  • TaxonomySession
  • TermStore
  • Group
  • TermSet

The code below will create a new group called "A Group" and then create a TermSet and populating the TermSet with items.  Here is the code:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPSite site = new SPSite(http://sp2010);
    TaxonomySession ts = new TaxonomySession(site);
    TermStore termStore = ts.TermStores[1];
    Group group = termStore.CreateGroup("A Group");
    TermSet termSet = group.CreateTermSet("Term Set 1");
    termSet.CreateTerm("Term 1", 1033);
    termSet.CreateTerm("Term 2", 1033);
    termSet.CreateTerm("Term 3", 1033);
    termStore.CommitAll();
});

Here is what the final output looks like when looking at it in Central Administration:

 

 About Bob Moore

ArchitectBob Moore is an architect for PointBridge. He has over 15 years of experience in the IT industry ranging from insurance to commercial printing and is currently focused on designing and developing cust... [more]

 Tag Cloud

 External Links

 ‭(Hidden)‬ Admin Links