#henrik

development and technology stuff

TimerJobs Deployment

Today I wanted to upgrade an existing custom TimerJob. After a stsadm -o upgradesolution everything seemed to be ok. But when the TimerJob was started it did not perform the way it should - in fact it used the wrong code/wrong logic - the same logic as before the upgrade. After some unsuccessful stsadm -o upgradesolution(s) later I almost gave up. But then I found a comment of a blog-post about custom TimerJobs. Finally the solution - actually it was quite obvious. If one deploys a new TimerJob it's always a good idea to restart the OWSTIMER service so that new assemblies are used.

Filed under  //   Sharepoint Development   moss   timerjob  

SPSite/SPWeb dispose

When working with the SharePoint object-model there is the issue to correctly dispose SPSite and SPWeb objects. There is a nice blog-post listing best-practice patterns. Today I found a tool which helps to find dispose issues in your code - the tool is called SPDisposeCheck. The tool analyzes libraries and executables and lists dispose issues. It can be nicely integrated into your build process by using the tool with the build events in visual studio.

Filed under  //   Sharepoint Development   moss   object-model  

MOSS: SAP incoming Email

For a MOSS/SAP project we needed a simple way to exchange SAP documents (order-confirmation, invoices, ...) with MOSS. The incoming email feature came in handy. Just define an email-address for the desired doclib and tell SAP to send emails including the documents as PDF attachments - sounds easy. The doclib was configured just to store the attachments and remove the original emails. After activation of this simple interface nothing happend. No attachments could be found in the doclib. First I tought that the emails were miss-routed, but the mail-server said everything was ok. I enabled to keep the original emails on the doclib. Now a number of emails were saved, but no attachment anyway. Strange! Saving the .eml messages and opening them with Outlook, Thunderbird, ... did work - the attachments (PDFs) were included - or using vim - showed a plain MIME-message with base64 encoded attachment. But there seemed to be something wrong with the MIME-message because MOSS did not recognise the attachment. I decided to parse the message myself - using a MIME library for .NET. Google found a codeproject site with a rather good example including a complete MIME library. The Lumisoft.Net library is really easy to use. I created a small test-program to find out what's wrong with the SAP MIME-message. Soon I found the problem. It seems that the SAP MIME-message includes a number of NULL-bytes which causes the Base64 decoder to throw an Exception.

Mime message = Mime.Parse(@"..\..\SAP_MIME.eml");
byte[] bytes = message.MainEntity.DataEncoded;

// without trim decode fails with exception
Encoding enc = Encoding.Default;
string myString = enc.GetString(bytes);
myString = myString.Trim('');
byte[] decoded = Base64DecodeString(myString);

After removing the trailing Null-bytes the bas64-encoded attachment could be extracted. To process all the files in the doclib I needed a timer-job anyway so I added the simple MIME-parsing/cleanup code to the timer-job. Everyhting works like a charm know. SAP and Microsoft - some times I think those two companies don't want things to be easy.

Filed under  //   SAP   Sharepoint Development   c#   moss