CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

SharePoint 2010 My Sites

Posted by Clayton James on April 11, 2011

There are two main area associated with My Sites.

  1. My Site Host Site Collection – Shared by all users – My Profile link – First site collection created in My Site web application
  2. My Site Personal Site Collection – Personal site collection – created when users click on the My Profile link – subsequent site collections in the My Site web application – can disable

The My Site Host Site Collection is easily customised and branded as this site collection it is shared by all users. There is a great article explaining it here.
http://blogs.msdn.com/b/spsocial/archive/2010/04/08/customizing-my-sites-in-microsoft-sharepoint-2010.aspx

The My Site Personal Site Collection is created for each individual user thus customisation is not so easy. A developer is required here as the solution here is known as Feature Stapling.

Feature Stapling allows a Feature to be called when a Site Template is called during the provisioning process. This means you can run some code to change master pages, apply custom security, etc… to the site during the provisioning process. So when the site is displayed to the user all of the changes you implemented in your Feature has been applied.

I have just finished implementing a solution for a client which I am happy about as Personal Sites are now branded and users are not site collection administrators.

This post while written for SharePoint 2007 is still very relevant for SharePoint 2010
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=794

Posted in .NET 2.0 | 10 Comments »

Remove Reply Text in SharePoint Discussion Board

Posted by Clayton James on December 9, 2010

Including the reply text in a SharePoint 2007 discussion board I think makes viewing and participating in discussions more clearer.

The following JavaScript will remove the reply (previous post) text.

var d = document.getElementsByTagName(“textarea”);
for( var i=0; i < d.length; ++i){
if( d[i].id.indexOf(‘TextField’) != 0 ){

d[i].value = ” “;

}
}

Posted in .NET 2.0 | 9 Comments »

Setting up SharePoint to use the ASP.Net Charting Control

Posted by Clayton James on October 27, 2010

Scott Gu discusses the very cool ASP.Net Chart Control and provides links to download the required components.

If you are developing custom applications in SharePoint 2007 are are interested in displaying your data in a graphical format (like this) then you will need to complete some configuration first.

Note: Make sure you download and install the Sample Applications as this has many great examples.

To setup the Charting in SharePoint you will need to perform the following:

  1. Download and install MSChart.exe on the SharePoint Server
  2. If you are in a development environment then also install MSChart_VisualStudioAddOn.exe
  3. Add Reference to the System.Web.DataVisulization.dll
  4. Update the SharePoint web.config file
    1. <handlers…section
      <remove name=”ChartImageHandler”/>
      <add name=”ChartImageHandler” preCondition=”integratedMode” verb=”GET,HEAD” path=”ChartImg.axd” type=”System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
    2. <appSettings…section
      <add key=”ChartImageHandler” value=”Storage=file;Timeout=20;Url=/_layouts/Images/MicrosoftChartControls/;”/>
    3. <controls…section
      <add tagPrefix=”asp” namespace=”System.Web.UI.DataVisualization.Charting” assembly=”System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
    4. <httpHandlers…section
      <add path=”ChartImg.axd” verb=”GET,HEAD” type=”System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ validate=”false”/>
    5. <tagPrefix…section
      <add tagPrefix=”asp” namespace=”System.Web.UI.DataVisualization.Charting” assembly=”System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
  5. Create the _layouts/Images/MicrosoftChartControls folder and provide higher permissions so everyone can modify
  6. Add POST to the httpHandlers ChartImg.axd to remove the error “Error executing child request for ChartImg.axd”

Posted in .NET 2.0 | 4 Comments »

SharePoint Resource Capacity Planner – Update

Posted by Clayton James on October 19, 2010

This application has gone live and I have added some nice functionality since the previous blog post:

  • All information is stored inside SharePoint lists
  • The Unavailable section is automatically updated from the SharePoint Leave Calendar (removing weekend hours)
  • Project capacity is selected from a dropdown list using a custom field control. This control is populated from the Projects site which lives in another web application
  • Heatmap functionality based on department or individual teams

Here are some screen shots:

Capacity Planner Image

Capacity Management

Heat Map Image

Heat Map Image

Posted in .NET 2.0 | 2 Comments »

Retreive SharePoint SPFieldChoice values

Posted by Clayton James on September 28, 2010

If you ever wanted to retrieve a collection of SPFieldChoice values then you can use the following code:

public static StringCollection GetEventCategoryChoices(SPWeb web)
  {
   SPList leaveList = web.Lists[LeaveCalendar.ListName];
   return ((SPFieldChoice)leaveList.Fields[Fields.EVENT_CATEGORY]).Choices;
  }

Posted in .NET 2.0 | 2 Comments »

Enum value with spaces c#

Posted by Clayton James on September 8, 2010

Have you ever wanted to display a friendly Enum name that included spaces.

C# doesn’t allow spaces in Enum’s, just like variables. However, thanks to c# extension methods we can create a new method that returns the Description Attribute.

Apply descriptions which may be different to the enum value. Notice the space.
public enum WorkType

{
[Description(“Service Delivery”)]
ServiceDelivery,
Project,
Unavailable
}

Create the extension method
//used to get the description from enum fields
public static string GetDescription(this Enum value)
{
Type type = value.GetType();
string name = Enum.GetName(type, value); if (name != null)
{
FieldInfo field = type.GetField(name);
if (field != null)
{
DescriptionAttribute attr =
Attribute.GetCustomAttribute(field,
typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attr != null)
{
return attr.Description;
}
}
}
return null;
}

Use it in your code
string serivceDelivery = WorkType.ServiceDelivery.GetDescription();

Posted in .NET 2.0 | 1 Comment »

SharePoint Resource Capacity Planner

Posted by Clayton James on September 7, 2010

I have recently began work on developing a Capacity Planning tool for a government agency in SharePoint. This work is only a couple of days in but I thought I would share something I learn’t today in relation to charting/graphing.

If you are running .net framework 3.5 sp1 and VS2008 then you are in luck to use Microsoft’s free charting platform with Visual Studio add-ons and very complete sample project. This fantastic news and a great addition to business solutions.
read about it here:

Note: The Chart control is built into VS2010 so no configuration or installation is necessary.

The chart currently displays dummy data but will in the future graph the data that is inside the grid.

Capacity Screen Shot

Posted in .NET 2.0 | Leave a Comment »

Moving Content Database between Farms

Posted by Clayton James on July 29, 2010

I found this from a MFST guy and I am storing it for future reference
http://blogs.msdn.com/b/toddca/archive/2009/01/30/preparetomove-away-from-running-this-command.aspx

I have done what you have said consistently several times without running PrepareToMove.  

Create the new web apps in your DEV environment first making new databases for them.  

Detach these 2 new content databases you created by making your new web apps from your SharePoint farm.

Have your DBA (or you can do it yourself if you know how) restore the content from the 1 old content databases to the 2 new content databases.  

When the restore is complete, reattach the 2 new databases you just refreshed to your farm using the AddContentDB command in STSADM.  Make sure to add -assignnewdatabaseID and -clearchangelog parameters to the AddContentDB command.  

Check the SiteSynch table in your SSP Service database as indicated above and if the ‘Moving’ column is TRUE, run the PrepareToMove STSADM command using the -contentDB command with the name of your new content DB and the -undo parameter.  Do this -undo command 2 times, once for each new contentDB.  

This worked for me when I had to refresh 2 separate databases in my DEV farm from 1 production content database.

Posted in .NET 2.0 | 2 Comments »

SharePoint Audit Log

Posted by Clayton James on July 29, 2010

I noticed our SharePoint content database growing at a rate that didn’t match the content being added. I decided to look at some table storage and ran the SQL Server 2008 reports from Management Studio and ran the Disk Usage report. Fantastic report detailing table size, number of records, etc…

One table that stood out was the AuditData table which was 50Gb in size. SharePoint Auditing can take up so much database space especially if you are auditing an entire site collection. Auditing was capturing data since late 2007 and wasn’t being used at the company, so the decision to disable this functionality. Great…save space and system resources.

So I turned it off at the site collection in site settings.

So the next step moved to how do we remove these logs?

  • Truncate the table – fast but unsupported and I am not sure what state this will leave you in
  • Object Model – write code to remove entries
  • stsadm trimauditlog- only available after SP2 – This is the one I selected

Stsadm trimaudtilog
http://technet.microsoft.com/en-us/library/cc706881(office.12).aspx

 I used the –url parameter instead of the -database parameter. I was receiving an object reference not set to an instance of an object error when using the -database parameter. I am not sure if it was because the site collection was migrated to a different database server and the audit logs was stored against a different database server.

I ran this command in 1 monthly intervals (which was painful) as there was a lot of data to clean up and the SQL database log file wouldn’t consume all the disk space. I would then manually shrink the log file DBCC ShrinkFile after every trim to free up space. I performed this action until the entire AuditData table was cleared.

So if your Content database is growing at an alarming rate then make sure you check your AuditData table and assess if you really need auditing enabled, especially for the entire site collection.

Posted in .NET 2.0 | 1 Comment »

Recursive loop treeview control

Posted by Clayton James on May 27, 2010

I am doing some work with the treeview control for displaying and selecting rooms in applications. When working with the treeview control you usually don’t know how many different levels of nodes you may be working with. Here are a couple of methods that will loop through all nodes in your treeview control.

private void RecurseNodes()
  {
   foreach (TreeNode parentNode in locationsTreeView.Nodes)
   {
    if (parentNode.ChildNodes.Count > 0)
    {
     RecurseChildren(parentNode);
    }
   }
  }

  private void RecurseChildren(TreeNode tn)
  {
   if (tn.ChildNodes.Count > 0)
   {
    tn.SelectAction = TreeNodeSelectAction.None;
    foreach (TreeNode tnC in tn.ChildNodes)
    {
     RecurseChildren(tnC);
    }
   }
  }

Posted in .NET 2.0 | 1 Comment »

Formulas and Functions for SharePoint Foundation

Posted by Clayton James on February 16, 2010

Here is a list of currently supported formulas and functions for SharePoint Foundation 2010.

http://officebeta.microsoft.com/en-us/sharepoint-foundation-help/CH010372694.aspx

Posted in SharePoint 2010 | 3 Comments »

SharePoint 2010 PowerShell Commands

Posted by Clayton James on February 9, 2010

PowerShell will become the favoured tool to use when administering SharePoint farms. While stsadm.exe will still be around in SP 2010 I don’t think it will progress to much further. I also don’t feel that it will be extended with custom commands as PowerShell will fill this role nicely.

So in short…learn PowerShell if you are a SharePoint Admin or Developer.

To get a list of all SharePoint 2010 PowerShell commands you can do the following.

In the SharePoint 2010 Management Console enter the following code:

Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” | format-table name > C:\SP2010_PowerShell_Commands.txt

Posted in SharePoint 2010 | Leave a Comment »

SharePoint Client Object Model

Posted by Clayton James on February 9, 2010

I have just been reading up on the SharePoint Client Object Model. This will really allow developers to deliver rich, interactive applications using a common API.

One of the nice developer features of SharePoint is that it does provide a rich Server Object Model which transcends into consistent code across projects and organisations.

Now we will also have a Client Object Model which will provide a consistent way to develop against SharePoint whether it be from a WPF application, Silverlight or Javascript application.

Here is a nice article explaining the mechanics of it all.

http://msdn.microsoft.com/en-us/library/ee857094(office.14).aspx

Posted in SharePoint 2010 | Leave a Comment »

Retrieving data from InfoPath repeating tables

Posted by Clayton James on November 3, 2009

When trying to retreive and view data from InfoPath repeating tables using a no code solution you have a couple of options.

1.
When publising your form you can select the column in the repeating table and modify the column function from (first) to (merge). This merges all the repeating values into one column so you can see all the values in your SharePoint View. One problem with this approach
is that the output doesn’t contain a delimiter for each column value so this makes it difficult for reporting

2.
Another option is to add a textbox to the form which will concatinate the values and seperate them via a deliminator (in this case a semi-              colon ‘;’).

In the value area of the textbox add the following formula.
xdMath:Eval(xdMath:Eval(/my:travelRequest/my:trips/my:trip, ‘concat(concat(concat(my:Airline_Name, concat(” – “, my:Flight_Identifier)), concat(” – “, my:Destination_EndDate)), “;”)’), “..”)

This outputs “Air France – GL3444 – 2009-11-05;Qantas – DJ3456 – 2009-11-27;”

To display this information in a SharePoint view you need to create a column in the Form Library for example FlightDetails and when you publish the form add a column mapping that maps FlightDetails to your textbox identifier.

Fill out a form and view the Flight information in a SharePoint view concatenated via a semi-colon. Now we have a ‘;’ deliminator we can easily extract/filter data when exported to an excel spreadsheet.

If you want to you can hide the textbox so users don’t see the value when filling out the form.

Posted in .NET 2.0 | 28 Comments »

Paging and Sorting GridView Control

Posted by Clayton James on October 19, 2009

If you implement paging and sorting in a GridView control then you need to maintain column level sorting when you move between pages.

I apoligise for the code formatting but wordpress doesn’t format code blocks very well.

General Methods
//
general method to bind grid. Pass in true if this method is called from the page index event
protected void GridBind(bool IsPageIndexEvent)
{
    GridRequests.DataSource = SortDataTable(GetRequestsDataTable(LoginCode), IsPageIndexEvent);
    GridRequests.DataBind();
}

 //get the data from the database and return a DataTable
protected DataTable GetRequestsDataTable(string LoginCode)
{
    Requests business =
new Requests();
    return business.GetUsersRequests(LoginCode).Tables[0];
}

//sort the DataTable and maintain sort direction if called from page index event
 protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
{
    if (dataTable != null)
    {
        DataView dataView =
new DataView(dataTable);
        if (GridViewSortExpression != string.Empty)
        {
            if (isPageIndexChanging) //pass in true if event fired from pageindex event
            dataView.Sort =
string.Format(“{0} {1}”, GridViewSortExpression, GridViewSortDirection);
        else
            dataView.Sort = string.Format(“{0} {1}”, GridViewSortExpression, GetSortDirection());
        }
        return dataView;
    }
    else
        return new DataView();
}
 
Sorting
Set the AllowSorting property to ‘true’ for the GridView
Set a couple of properties to maintain sort column and direction across postbacks
 
private string GridViewSortDirection
{
    get { return ViewState[“SortDirection”] as string ?? “ASC”; }
    set { ViewState[“SortDirection”] = value; }
}

private string GridViewSortExpression
{
    get { return ViewState[“SortExpression”] as string ?? “Request Id”; }
    set { ViewState[“SortExpression”] = value; }
}

//this method is called to alternate sort direction
private string GetSortDirection()
{
    switch (GridViewSortDirection)
    {
        case “ASC”:
            GridViewSortDirection = “DESC”;
            break;
        case “DESC”:
            GridViewSortDirection =
“ASC”;
            break;
    }
    return GridViewSortDirection;
}

 
//alternate sort direction and maintain page index
void GridRequests_Sorting(object sender, GridViewSortEventArgs e)
{
    GridViewSortExpression = e.SortExpression;
    int pageIndex = GridRequests.PageIndex;
    GridBind(
false); //pageindex event did not fire binding
    GridRequests.PageIndex = pageIndex;
}

 
 
Turn paging on in the GridView control and wire up the Grid_PageIndexChanging eventprotectedvoid GridRequests_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridBind(
true);//maintain sort direction as we are only navigating between pages
    GridRequests.PageIndex = e.NewPageIndex;
    GridRequests.DataBind();
}

Posted in .NET 2.0 | 7 Comments »

SharePoint Designer Training

Posted by Clayton James on October 14, 2009

I am currently up in the sugar capital of Australia, Mackay delivering a 3 day SharePoint designer training course.

Lots of cool things learned:

  • Embedding/displaying videos from a document library in a web page
  • Branding: Custom master page design, CSS and overriding core.css
  • Integrate Twitter into your site
  • DataView Web Part: integration with databases, web services and rss (and sharepoint rollups)
  • IE Developer Toolbar is your best friend

And why are those Fab 40 templates so crap!

Posted in MOSS 2007, Presentaitons | Leave a Comment »

Security Trim "View All Site Content"

Posted by Clayton James on July 28, 2009

I have been asked this a few times. How can I remove the View All Site Content link for certain users?

The View All Site Content link can be a great navigational link or a problematic link that confuses end users.
image

The default security setting for this SPLinkButton is set to be displayed to everyone…and when I say everyone I mean everyone…viewers and even anonymous users. This is found in the master page in your site.

  1. Open up the master page in SharePoint designer
  2. Place the page into split view
  3. Click the View All Site Content link and in you code window you should see the following

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ViewFormPages”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>
</SharePoint:SPSecurityTrimmedControl>

 

Thankfully we can easily upgrade the security to different security level. For example, if we change the PermissionsString=”ManageWeb” then only users who have this permission level (site admins) will see the View All Site Content link.

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>
</SharePoint:SPSecurityTrimmedControl>

 

There are a number of different permission levels that you can view here.

The SharePoint:SecurityTrimmedControl is a handy control that can be used in many locations. For example, wrap it around the Site Actions control for custom and you remove this control based on security.

Posted in WSS 3.0 | 22 Comments »

Test in Multiple Browsers

Posted by Clayton James on May 29, 2009

This has always been a problem for developers with requirements to support multiple browsers. When writing code various browsers render the exact same peice of code differently. So the development process consists of programming workarounds so they render the same or very similar.

Now we have a free tool that we can use to test multiple browsers easily during our development process.

http://www.xenocode.com/browsers/

Posted in .NET 2.0, .Net 3.0 | 2 Comments »

Add .Net User Controls to SharePoint

Posted by Clayton James on May 25, 2009

I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.

  1. I have a Graphical User Interface
  2. I have a separate project to build and test outside of SharePoint
  3. I can easily update and view my project html and binary code

Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.

  1. Create a VS2008 web project
  2. In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
  3. In your VS2008 project create some user controls and test that they function
  4. In VS2008 project properties under the Build Events tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008 project. I had problems when I put the VS2008 project .dll into the GAC…it only worked when I put it into the SharePoint’s web sites bin directory
  5. Update your master page with CSS references if your VS2008 project contains a style sheet.
  6. In SPD in your Page Layout add a Register directive to register your user control
    “<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
    OR
    Update the SharePoint web site web.config file
    <pages>
      <controls>
            <add src=”~/UI/UserControls/MyAttributes.ascx” tagPrefix=”uc1″ tagName=”MyAttributes”/>
            <add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
        </controls>
    </pages>
  7. Add the User Control to the Page Layout
    <uc1:JobGoals ID=”JobGoals1″ runat=”server” />
  8. Update the SharePoinnt web sites web.config file
    <SafeControl Src=”~/UI/*”  IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
  9. Restart IIS, navigate to a page that uses the page layout and you should see your User Control

Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.

  1. .ascx changes:                modify, save in VS2008 and refresh sharepoint browser
  2. .ascx.cs changes:          modify, save, build  in VS2008 and refresh sharepoint browser

Posted in .NET 2.0, .Net 3.0, WSS 3.0 | 4 Comments »

User Group Presentation – Content Query Web Part – Part 2

Posted by Clayton James on May 20, 2009

I completed my Part 2 presentation on the CQWP today. I thought that the rain may have kept the numbers down so it was great to see a good turn out.

Topic Covered:

  • How and where best to use – plan ahead
  • Displaying extra columns in result set
  • Modifying the ItemStyle.xsl and .webpart files
  • XSLT
  • Tips and tricks – (thanks Tim for the select=.) tip
  • Subclassing using Visual Studio
  • Deployment

 

I always need more time presenting at user groups.

Slide deck and demos will be uploaded to the BSPUG site soon.

Posted in MOSS 2007, Presentaitons | 1 Comment »