Tuesday, July 27, 2010

Sharepoint 2010 and Silverlight

Well I have been busy for the last 5 months doing SharePoint 2010 development and Silverlight. Below are links to some MSDN channel 9 videos of what my team and I have been doing in regards to ECM and Search. The videos show some of our products in the beta stage. The release of KnowledgeLake Imaging 2010 is very soon. I will be posting more information about the things we implemented in this product.

KnowledgeLake Search Center

KnowledgeLake Viewer

KnowledgeLake SharePoint development with VS2010 and Silverlight

Monday, July 5, 2010

Adjusting date time values in SharePoint 2010

Technorati Tags: ,,

It is well known that SharePoint stores date time values in GMT(Greenwich Mean Time). This is done in order for SharePoint to adjust date time values according to site or user regional setting preferences. On a recent project I had to determine how to adjust date time values returned from search results, for example the “Last Modified” value for a document. The value is returned in GMT time and users complained it was not the same value as what was showing in the document library in SharePoint.  Below is a picture of list of time zones SharePoint displays to choose from when setting the regional settings for a Site. Notice some time zones are listed with a negative number of hours compared to the GMT time and others are listed with a positive number.

SharePoint exposes the SPTimeZoneInformation class to enable your code to make the same regional setting adjustments as the UI. Below is code showing you how to use this class, along with the logic to adjust for daylight savings time. The strange thing is that the Bias value is opposite of the value displayed in the time zone list. For example, central time is listed as being 6 hours behind GMT, however the value for the Bias which is in minutes is a positive value. Conversely, the Bias value for Amsterdam which is listed as an hour ahead of GMT is a negative value. So you must reverse the sign of the value before adjusting the date time value.


           int timeZoneBiasMinutes = 0;

           DateTime newVal;

           DateTime tmpVal = DateTime.Now;

           if (SPContext.Current != null && SPContext.Current.Web != null)
               SPTimeZoneInformation info =
               timeZoneBiasMinutes = info.Bias;

               DateTime now = DateTime.Now;
               SPSystemTime daylightDate = info.DaylightDate;

               if(now.Month >= daylightDate.Month)
                   if(now.Day >= daylightDate.Day)
                       timeZoneBiasMinutes += info.DaylightBias;

               if (timeZoneBiasMinutes > 0)
                  minAdjustment = -timeZoneBiasMinutes;
                  minAdjustment = Math.Abs(timeZoneBiasMinutes);

               newVal = ((DateTime)tmpVal).AddMinutes(minAdjustment);

Friday, July 2, 2010

SharePoint 2010 and Silverlight (Downloading a file with the client object model)

Technorati Tags: ,,

When I was doing SivlerLight 2 development and using SP2007, I was wishing for a cleaner way of downloading a file. It just seemed so browser like to stream a file via the response stream and force the browser to pop open two dialogs like below. I had worked so hard on making the Silverlight application not to look like a traditional browser based application, it just seemed to be a shame.

Well when I was doing Silverlight 4 and SP2010 development I came across the SilverLight System.Windows.Controls.SaveFileDialog class. This is just like using the Windows.Forms.FileDialog class of old days except for Silverlight. Very nice, because you just get the save file dialog  without all the extra windows, making it behave more like a desktop application.


So I needed some code to get a file from SharePoint and then prompt the user with the SaveFileDialog. Remember everything must be called asynchronously in Silverlight. The code below uses the Sivlerlight client object model File.OpenBinaryDirect along with an “in-line” anonymous delegate allowing the callback code to be executed in the same method. Works out very well.

       private void DownloadFile(string path)
           string filterTemplate = "!@Ext Files (*.!@Ext) | *.!@Ext";
           SaveFileDialog dialog = new SaveFileDialog();
           dialog.DefaultExt = Path.GetExtension(path).Substring(1);
           dialog.Filter = filterTemplate.Replace("!@Ext", dialog.DefaultExt);

           bool? result = dialog.ShowDialog();

           if (result.HasValue && result == true)
               this.Busy = true;
               Stream sourceStream = null;
               Uri fileUrl = new Uri(path);

               ClientContext clientContext =
                   new ClientContext(fileUrl.GetComponents(

               Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileUrl.AbsolutePath,
                   (object eventSender, OpenBinarySucceededEventArgs eventArgs) =>
                       if (eventArgs.Stream != null)
                           sourceStream = eventArgs.Stream;
                       Deployment.Current.Dispatcher.BeginInvoke(() =>
                           using (Stream destStream = dialog.OpenFile())
                               byte[] bytes = new byte[sourceStream.Length];

                               sourceStream.Read(bytes, 0, (int)sourceStream.Length);
                               destStream.Write(bytes, 0, bytes.Length);

                           this.Busy = false;

                   }, null);             


Thursday, July 1, 2010

SharePoint Server MVP 2010

Technorati Tags: ,,

Well I am blessed and fortunate enough to have my SharePoint MVP renewed for 2010. I am looking forward to sharing a lot of knowledge regarding SP2010 in the future. Once again I want to thank KnowledgeLake for giving me the opportunity to push the SP2010 envelope. Stayed tuned to see the amazing things we are doing here at KnowledgeLake with SharePoint, Search, SilverLight and Document Imaging.