Simonsens blog
Tuesday, January 5, 2010
SharePoint calculated columns and variations?
On a list in an English variation I have a calculated column called CalculatedExpiry with a formula that looks like this:
=IF(Expires="",DATE(2099,1,1),Expires)
and that works just fine, if the Expires field is empty, it set it to 1. January 2099
I then created the same calculated column on a Danish variation of the site, but when I wanted to save it I got the "The formula contains a syntax error or is not supported."
Even though they where identical...
After a lot of testing and googling I came accross this post, which suggested to replace the commas (,) in the formula with semicolons (;) and what do you know, it works!
So in the Danish variation the calculated columns formula now looks like this:
=IF(Expires="";DATE(2099;1;1);Expires)
Sunday, December 20, 2009
Installing SharePoint 2010 on Windows Vista x64 SP1
However I managed to complete the wizard by removing the two allowInsecureTransport="true" sentences (remember not to remove the closing tag :)) from the client.config found at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile" thanks to a tip from http://www.mcpblog.net/Lists/Posts/Post.aspx?List=8f2497f6%2De77b%2D4e70%2D8400%2De020b292165c&ID=61. Note that you don't have to uninstall SharePoint, only remove the two lines.
Jesper Simonsen
Wednesday, March 11, 2009
Creating a document expiration view
Monday, March 9, 2009
To Dispose or not to Dispose - that's the question
.NET Runtime version 2.0.50727.3068 - Fatal Execution Engine Error. The error assumed problems with the dotnet framework, but repairing the framework and applying hot fixes didn't solve the issue. And the strange thing was that it was only when adding new item it happened, where as the workflow ran perfectly when updating items. The major difference was that the item adding was triggered from an eventhandler and therefore ran under the System account, but item updating occurred when a user changed the document. I also discovered that part of the workflow ran, before it died, so I put in excessive logging and ended up at a SPWeb.Dispose line. Once I commented out these lines the error disappeared.
// Disposing here will cause workflow to fail
// web.Dispose();
Friday, February 20, 2009
Cascading dropdown lists and error 401
Wednesday, February 11, 2009
Creating logging for workflows and eventhandlers
I use the same logging feature and logging place for all of our workflows and our one and only Construction Kit Eventhandler (more on that another day). It's fairly simple, but functionally enough to keep me going.
So in the terms of C#:
- Make two global variables
public int i = 0;
StringBuilder MyStringBuilder = new StringBuilder(); - Create two functions
public void AddToLog(string msg)
{
MyStringBuilder.AppendLine(DateTime.Now.ToLongTimeString() + ":" + i.ToString() + "=" + msg);
}
public void WriteLog()
{
try
{
AddToLog("Log ended at i = " + i.ToString());
SPList SetupList = web2.Lists["Logs"]; //use global SPWeb here or hardcode
SPListItem myItem = SetupList.Items.Add();
myItem["Title"] = myContentType;
myItem["Log"] = MyStringBuilder;
myItem.Update();
SetupList.Update();
}
catch (Exception Ex)
{
//Even logging can fail so you may want to take some action here
}
} - In your code place a code counter and code logging like this:
AddToLog("ReadSettings started...");
i = 1;
myUrl = workflowProperties.WebUrl.ToString();
i++;
AddToLog(" Url: " + myUrl);
i++;
Etc...
The code counter 'i' gives you the option of pin pointing exactly at which line of code the error occurred. - At the end of your code execution and at your global error handling code ensure to get the log written:
WriteLog();
The Logs list should contain two columns, 'Title' as Single line of text and 'Log' as Multiple lines of text (plain text).
Now you can hardcode your logging destination into the WriteLog function or you can setup a global SPWeb object (remember to dispose it at the end of the code execution) like I do. My code look something like this:
string myUrl = workflowProperties.WebUrl.ToString();
i++;
int startcmd = myUrl.IndexOf("//");
i++;
int startval = myUrl.IndexOf("/", startcmd + 2);
if (startval == -1) startval = myUrl.Length;
i++;
SPSite objSite = new SPSite(myUrl.Substring(0, startval).ToLower().Replace("corporate", "collaboration") + "/SubFolder/Settings");
i++;
web2 = objSite.OpenWeb();
i++;
The .Replace("corporate", "collaboration") trick is about having two different webs served by the same code, but only having one place to host the logging, e.g. at http://collaboration/SubFolder/Settings/Logs
Obviously our logging code also deals with log archiving, success or failiure logging as well as notification of sys admins, but for the sake of simplicity this is the starting point.
Display the version number on your InfoPath form
Here's a simple trick to display the info.
- On your form find a suitable place to add a textbox (I place mine at the bottom, right corner)
- In the new textbox property, click the Fx button and insert the following in the formula box:
concat(substring-before(substring-after(processing-instruction()[local-name(.) = "mso-infoPathSolution"]; 'href="'); '"'); " template with form version "; substring-before(substring-after(processing-instruction()[local-name(.) = "mso-infoPathSolution"]; 'solutionVersion="'); '"')) - Now you can format the textbox with text color, size (use 'auto' as width) and position.
I found parts of this somewhere on the net, so don't blame me if it works :-)