CJ

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

  • Past Post

  • Vistor Locations

Archive for the ‘.NET 2.0’ Category

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 | 9 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 | 8 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 | 2 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 | 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 | 22 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 | 6 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 »

Accessibility Resources

Posted by Clayton James on May 15, 2009

A list of useful accessibility resources

Microsoft ASP.Net

SharePoint Specific

Tools

Posted in .NET 2.0 | 1 Comment »

Handling.Net DataSets correctly

Posted by Clayton James on March 18, 2009

One of the most common programming issues I see when working at clients locations is the way the common .Net DataSet is managed. I see a lot of code written like the first example below which checks if the DataSet table contains any rows. The problem with Example 1 is it expects a couple of things. Firstly that a DataSet (ds) even exists and secondly that it also contains a table. This code will throw an exception if the DataSet is null or no DataSet table exists.

Example 1
//this will throw an exception if ds is null or no table exists
if(ds.Tables[0].Rows.Count > 0)
{
            //process data
}

Example 2
So you should write your code checking of empty rows, empty tables and if the DataSet object exists.
if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
            //process data
}
else
{
         // it is empty
}

 

Happy Coding! :)

Posted in .NET 2.0 | Leave a Comment »

IFrame Resize and SharePoint

Posted by Clayton James on March 3, 2009

I created a custom IFrame web part that has a dynamic source property. The client wanted the IFrame to dynamically resize itself to the browsers width and height.

 

To achieve this we needed to place the web part directly into the page i.e don’t use a webpart zone. A web part zone wraps tables around the IFrame and controls the width and height properties.

 

I read a few articles about using JQuery….may have to give this a go also.

Posted in .NET 2.0 | 1 Comment »

User Group Presentation

Posted by Clayton James on February 17, 2009

I will be presenting at my local SharePoint user group tomorrow. This will actually be my first SharePoint user group presentation so I am really looking forward to meeting some new people and seeing what is happening in the SharePoint space.

I am talking about the Content Query Web Part and the abstract is below.

Leveraging the Content Query Web Part

Come and learn how to configure one of the most important MOSS web parts in your toolkit. We will walk-through SharePoint’s premier OOTB rollup web part and demonstrate how to display results in 2 or 3 column format and have multiple fields returned in the results. We will also open Visual Studio and demonstrate how to extend its functionality with paging and dynamic filtering.

 

If you would like to attend then the details are below.

clip_image001

Posted in .NET 2.0 | 1 Comment »

CAS & Web Parts

Posted by Clayton James on January 10, 2009

Brett Lonsdale has done some great work in documenting CAS in SharePoint. I recently used two of his articles to get my assemblies working.

http://www.brettlonsdale.com/spblog/Lists/Posts/Post.aspx?ID=7

http://www.combined-knowledge.com/Downloads/Code%20Access%20Security%20in%20SharePoint%202007%20for%20Administrators.pdf

 

The CAS Bible – old but still very relevant
http://msdn.microsoft.com/en-us/library/ms916855.aspx#sharepoint_wsscodeaccesssecurity_topic5

 

Great work from Patrick about grouping assemblies to share CAS policies using the same .snk file.
http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1798

 

Good explanation
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!1963.entry
http://dotnettipoftheday.com/Blog.aspx?Id=371

Posted in .NET 2.0 | 2 Comments »

SharePoint December Cumulative Updates

Posted by Clayton James on January 9, 2009

I have just updated my development (Single Server with SQL Server installed) SharePoint machine with the WSS and MOSS December updates. Note there are two updates if you are running MOSS.

To my surprise everything worked a treat.

I only had SP1 installed before I installed the December updates. I didn’t have the Infrastructure update or any other hotfixes installed before applying the updates.

Steps

  1. I installed the WSS update first.
  2. I didn’t run SharePoint Configuration wizard
  3. I installed the MOSS update
  4. I did run the SharePoint Configuration wizard

 

The great thing about the December update is that it includes all previous hotfixes from RTM.

Read and download them from here.
http://blogs.msdn.com/sharepoint/archive/2008/12/17/announcing-december-cumulative-update-for-office-sharepoint-server-2007-and-windows-sharepoint-services-3-0.aspx

Posted in .NET 2.0 | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 26 other followers