Sometimes you’ll get a javascript error “style.display is null or not an object” and as a result you’re unable to modify the certain random web part’s properties on the edit page. This is because the content of a Content Editor web part (CEWP) on the page has been copied and pasted from another CEWP and it has brought across some CSS script with it that is causing the error.

To fix the problem you need to delete the CEWP in question.  If you can’t delete it through the web part’s menu because of the error simply navigate to the page’s web part maintenance page by adding ?contents=1 to the page URL.

When you’re processing an event on the server you’ll often need to use the web’s regional settings for date and time rather than the server’s. Here’s a code snippet that was part of an ECB action that will allow you to do this:

using (SPWeb web = SPContext.Current.Web) {
  DateTime dtToday = DateTime.Now;
  DateTime regionDate = web.RegionalSettings.TimeZone.UTCToLocalTime(dtToday);
  DateTime completedDate = Convert.ToDateTime(SPUtility.FormatDate(web, regionDate,
    SPDateFormat.ISO8601));
}

Users will initially go through the process of bulk uploading documents into their shiny new SharePoint site, either through the ‘Upload Multiple Documents’ menu item or through Explorer View. Often they’ll run into the problem where once uploaded the document remains checked out and no one else can see it, and then have to go through the tedious process of individually checking them in one by one (as well as filling in the metadata!)

During this initial upload I’ll usually turn off all settings which will do this automatic check out, and only turn them on once that process has completed. This is a list of settings that you need to configure for this:

  • Select No for the ‘Require documents to be checked out before they can be edited?’ setting in Version Settings
  • Make sure all columns that have Yes to ‘Require that this column contains information’ have a default value, else select No for the column in question.

This tool will will inspect your SharePoint assemblies and check that you are correctly disposing of certain SharePoint objects (IDisposable objects which includes SPSite and SPWeb).  An extremely handy thing for developers and portal admins alike!

http://blogs.msdn.com/sharepoint/archive/2009/01/29/spdisposecheck-released.aspx

SharePoint is a perfect tool for lightweight project management. The Project Tasks list and its associated list view web part is a popular choice as it can display a Gantt chart of the tasks. However it is not very flexible in its display capabilities unlike its counterpart, MS Project.

One request I’ve had was the allow a weekly view of project tasks rather than the default daily view.  This can be achieved though writing CSS script such as Path To SharePoint explains, however the users want a button to toggle between a daily view and a weekly view depending on which project they are looking at. This can be achieved by inserting some Javascript into the page.

With the example below I’ve done this by utilising the jQuery javascript library:

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js” type=”text/javascript”></script>
<script>
$(function() {
var bt1=”<input id=’tlv0′ class=’ms-ButtonHeightWidth’ type=’button’ target=’_self’ value=’Toggle Daily/Weekly’ name=’togglelv’ style=’WIDTH: 140px’ />”;
$(“td.ms-toolbar[width='99%']“).append(bt1);
    $(“#tlv0″).toggle(
      function () {
        $(“table[class='ms-ganttInnerTable'] IMG”).css({“width”:”2px”});
        $(“.ms-ganttDetailTimeUnitRow”).css({“display”:”none”});
        $(“.ms-ganttMajorTimeUnitHeaderCell”).css({“writing-mode”:”tb-rl”,”filter”:”flipv fliph”,”border”:”0″});
      },
      function () {
        $(“table[class='ms-ganttInnerTable'] IMG”).css({“width”:”16px”});
        $(“.ms-ganttDetailTimeUnitRow”).css({“display”:”inline”});
        $(“.ms-ganttMajorTimeUnitHeaderCell”).css({“writing-mode”:”lr-tb”,”filter”:”none”,”border”:”0″});
      }
    );
  });
</script>

If you’ve created a custom Edit Control Block (ECB) menu item then often you want the code processed in an application page and then returned to the exact same page the user originated from. None of the URL tokens provided for the UrlAction element will do this so instead you can use a handy bit of Javascript to achieve the same thing:

<UrlAction Url=”javascript:window.location= ‘{SiteUrl}/_layouts/TMGTaskTracker/FastClose.aspx?ItemId={ItemId}&amp;ListId={ListId}&amp;Source=’ + window.location”/>

A more detailed explanation along the same subject lines can be found at Jan Tielens’ blog.

How do you specify the source list when doing a CAML query that covers more than one list? Using a tool like U2U CAML Query Tool to write your queries doesn’t specify any field that references the source list.  

To reference the list URL you need to use the FileDirRef field. Here’s some example code which includes logic that strips out the URL from the string that’s returned as it’s a Lookup field type:

query.ViewFields = @”<FieldRef Name=’FileDirRef’ Nullable=’TRUE’ />”;
urlValue = row["FileDirRef"].ToString().Substring(row["FileDirRef"].ToString().IndexOf(“#”) + 1);

I was getting errors when clicking on buttons like New and Settings within lists and only on a particular PC. To fix this I needed to install this IE update:

http://www.microsoft.com/technet/security/bulletin/ms07-027.mspx

Another thing which can cause the custom timer assembly to hang in the cache is when the assembly version remains the same. Make sure you use an auto-increment for your assembly version like so:

[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]

I was wanting to use methods on a date within a SharePoint field eg. Month, Add using the standard code for pulling back a datetime field from SharePoint

SPFieldDateTime dt = (SPFieldDateTime)list.Fields["Deadline"];

However the SPFieldDateTime field doesn’t have any of these methods. I needed to use the DateTime field type. If you try to change this code above to DateTime instead of SPFieldDateTime you’ll get the following error:

Cannot convert type ‘Microsoft.SharePoint.SPField’ to ‘System.DateTime’

To get around this you can pull the field directly out of the list using as it will be returned as an object and which you can then covert to a DateTime object.

DateTime dt = (DateTime)list["Deadline"];

The task method activity in a SharePoint workflow can assign it to a SharePoint user or group. And a subsequent email method activity will email this same user no problem, however it seems to stumble when it is a group. So what I did was use the following method to grab the email id’s from the group and then build a string using it for the email activity.

Check out the following email method and how it builds the string for the To field in the email header:

private void sendEmail1_MethodInvoking(object sender, EventArgs e)
{
//Create emails to the DB Site Owners
SPGroup admin = workflowProperties.Web.SiteGroups["DB Site Admin"];
StringBuilder builder = new StringBuilder();

foreach (SPUser user in admin.Users)
builder.Append(user.Email.ToString() + “, “);

completeMailHeader.Add(“To”, builder.ToString());
completeMailHeader.Add(“Subject”, “A new project request ‘” + workflowProperties.Item.Title + “‘ has been submitted to the pipline.”);
completeMailBody = “Please review the following task: ” + workflowProperties.WebUrl + “/Lists/Tasks/Dispform.aspx?ID=” + taskAfterProperties.TaskItemId;
}

Microsoft have created a new site dedicated to SharePoint best practices. About time! Check it out:

http://technet.microsoft.com/en-us/office/sharepointserver/bb736746.aspx

One of the biggest problems I’ve seen in production environments is code released that don’t dispose of SharePoint objects properly. This causes the whole portal to slow down and often the only solution is to schedule multiple recycles of the application pool per day. I’ve seen it time and time again. Only the most diligent (and competent) of portal administrators will pick up on it and refuse to release the code into production.

This can be eradicated by good coding practices which is one of the pages on the site mentioned above called “Best practices: Using disposable Windows SharePoint Services objects”. Ensure you include this as part of your development governance guidelines for your organisation.

http://msdn.microsoft.com/en-gb/library/aa973248.aspx

During a recent deployment into production we had issues with the release management team installing an an update to an assembly for an Excel Report that utilised UDF’s into the GAC and then restarting IIS and then the Excel reports not working as expected. It was instantiating the old assembly that was there before the new release; the updates to the UDF just weren’t appearing in production!

It turns out the release management team was only restarting IIS on the front end web servers. After much troubleshooting over the phone with these guys we figured out that an assembly that uses UDF’s also needs IIS restarted an every application server that hosts Excel Calculation Server.

Ensure you put this into your release producedure documentation to prevent late nights like I had!**

** Technically it wasn’t night – I was embellishing the truth. The release management team is situated in one of those zany European countries which has strict labour laws preventing a standard employee working past 5pm, and so all releases must be during business hours.

I’ve got a series of SharePoint custom site pages that are implemented through features. The pages are ghostable however not stored in libraries. This is a WSS implementation with no WCM capabilities.

Now I want to delete some of them from the production environment. However I cannot use SharePoint Designer in production as it’s been disabled (too right!) nor do I want to deactivate feature and remove the solution – how do I achieve this? After much research the answer was staring at me in the face!

How about mapping a web folder to the site collection URL in Windows Explorer and deleting the pages like you would any file on the network?

 If you want to create a mulituser column then you should not only declare the Type as “UserMulti” (obvious) but you also have to add an attribute Mult=”TRUE” to get it working (not obvious). I really don’t know why you have to, it’s not explained in the slightest in the SDK documentation. Here’s my example:

 <Field
    ID=”{5B9985AC-C959-458d-BE78-A464A013C0C9}”
    Name=”SecondaryBusinessSponsor”
    DisplayName=”Secondary Business Sponsors”
    Type=”UserMulti”  
    Group=”TMG Columns”
  Mult=”TRUE”>
  </Field>

Some blogs out there mention methods like GetSPUser to obtain the SPUser value for event receivers but what about using it in workflows? The following code also shows how this method can be used within an Email Activity method of a SharePoint workflow using the workflowProperties object.

private void sendEmail2_MethodInvoking(object sender, EventArgs e)
{
  //Create emails to the Regional Lead
  completeMailHeader.Clear();

  SPListItem projectItem = workflowProperties.Item;
  SPUser regionalLead = GetSPUser(projectItem,
    workflowProperties.List.Fields.GetField("CTBRegionalLead"));
  completeMailHeader.Add("To", regionalLead.Email);
  completeMailHeader.Add("Subject", "Project request '" + workflowProperties.Item.Title
    + "' needs Regional Lead approval.");
  completeMailBody = "Please review the following task: " + workflowProperties.WebUrl
    + "/Lists/Tasks/Dispform.aspx?ID=" + taskAfterProperties3.TaskItemId;
} 

private SPUser GetSPUser(SPListItem item, SPField field)
{
  string currentValue = item[field.Title].ToString();
  SPFieldUser userField = (SPFieldUser)field;
  SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(currentValue);
  return fieldValue.User;
}

I had a frustrating problem today with not being able to get the Named Item property in a EWA web part to recognise a chart within an Excel 2007 workbook. Further investigation showed that it was not showing up in the “Show Items in Workbook” list in the Excel Services Options when I was trying to publish the workbook to the SharePoint site. This indicated that them issue lay with the workbook itself.

After much trial and error I found the problem – Excel won’t publish a Named Item that is purely based upon a chart; it has to have some characters or numbers entered in cells within the named range. So I just put the title of the chart within the range in a cell and then the Named Item was published as expected. The EWA web part picked up the Named Item with no problems. And of course the chart obscured the title text I had put in anyway so it all worked out as I wanted in the end.

While using the Office Open XML package for writing reports I was receiving errors when grabbing list data and writing it to an Excel spreadsheet. An example would be an apostrophe in the string Jason’s Project would cause the following exception:

Error in Pipeline Dashboard Report. ‘//d:si[d:t='Jason's Project' has an invalid token.   at MS.Internal.Xml.XPath.XPathParser.ParseStep (AstNode qyInput)

To fix this edit the ExcelCell.cs file on line 456 to the following:

XmlNodestringNode = _xlWorksheet.xlPackage.Workbook.SharedStringsXml.SelectSingleNode (string.Format("//d:si[d:t='{0}']“, System.Security.SecurityElement.Escape(Value)), _xlWorksheet.NameSpaceManager);

When developing your own SharePoint Time Job Definition you may encounter an issue when you try and update the assembly in the GAC – it will run the original code you installed. This is despite a IISRESET as well.

To fix it and install your new code you will need to restart the OWSTIMER.EXE service as well as IIS by using the following commands:

net stop “Windows SharePoint Services Timer”
net start “Windows SharePoint Services Timer”

Next Page »

Follow

Get every new post delivered to your Inbox.