Tuesday, March 13, 2007

Shell Extensions - Context Menu

I couldn’t blog for long time due to some personal reasons. Hope I’ll be able to blog without any breaks in future. I'm going to write something different this time, Context Menu for explorer.

I wanted to write a context menu extension for the explorer using some Win32 API calls, which took me a while and it was really a pain. Had problems in debugging, needed to reboot the machine number of times, etc… So thought of coming up with a wrapper in .NET. The wrapper is mainly an abstract class which can be driven to create a personalized context menu extension. The assembly can be downloaded from
here and the source can be downloaded from here.

How To use Utils.ShellExtensions.ContextMenu.dll

Deploy Utils.ShellExtensions.ContextMenu.dll in gac. Create a class library project. Add Utils.ShellExtensions.ContextMenu.dll to your project. Drive a class from BaseContextMenu. Make it com visible, install it in gac and register it for com.


Example


[ComVisible(true), Guid("0056DA96-FFD6-4180-BAB2-8C9B6F552B2D")]
public class MyMenu : BaseContextMenu
{
     [ComRegisterFunction]
     public static void RegisterFunction(Type t)
     {
          //Register for files
          RegisterContextMenu.Register("*", t.GUID);
          //Register for folders
          RegisterContextMenu.Register("Directory", t.GUID);
          //Register for drives
          RegisterContextMenu.Register("Drive", t.GUID);
     }

     [ComUnregisterFunction]
     public static void UnregisterFunction(Type t)
     {
          RegisterContextMenu.Unregister("*", t.GUID);
          RegisterContextMenu.Unregister("Directory", t.GUID);
          RegisterContextMenu.Unregister("Drive", t.GUID);
     }

     public override void AssembleMenu()
     {
          System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(@"c:\test.bmp");
          System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(@"c:\test1.bmp");
          MenuItems menuItems1 = new MenuItems("Test1",0,false);
          MenuItems menuItems2 = new MenuItems("Test2",1,false,bmp,true);
          MenuItems menuItems3 = new MenuItems("Test3",2,false,bmp1,false);
          menuItems2.Click +=new Utils.ShellContextMenu.MenuItems.MenuClickHandler(menuItems2_Click);
          menuItems3.Click +=new Utils.ShellContextMenu.MenuItems.MenuClickHandler(menuItems3_Click);
          //This order is important. Always insert the parent container and then the child!
          InsertMenu(menuItems1);
          AddMenu(menuItems1, menuItems2);
          AddMenu(menuItems1, menuItems3);
     }

     private void menuItems2_Click()
     {
          System.Windows.Forms.MessageBox.Show("Menu Test2 clicked");
     }

     private void menuItems3_Click()
     {
          System.Windows.Forms.MessageBox.Show("Menu Test3 clicked");
     }
}

Labels: , ,

Sunday, June 25, 2006

MCMS Manager 6.2

This release is for users who want MCMS Manager to be worked with .NET framework 2.0. Also from the previous version, MCMS Manager works with MCMS 2002 SP2. In future if necessary otherwise there wont be any releases for .NET framework 1.1 (I'm really struggling to manage my time).

Get the new version from here. For more information check MCMS Manager Site. Please don't forget to post your feedbacks.

Labels:

Monday, June 19, 2006

MCMS Manager 6.1

After a while.. This version includes,

1. Adding Resource(s).
2. Windows Authentication support.
3. Authentication for the web service & more.

Get the new version from here. For more information check MCMS Manager site. Please don't forget to post your feedbacks here.

Labels: , ,

Sunday, March 19, 2006

MVP for Microsoft Office Content Management Server (MCMS)

I got a mail (not email - parcel - with certificate) from Microsoft stating that I got awarded as MVP for MCMS!

I want to thank Stefan, Spancer, Mei Ying, Andrew, Angus and Jole Ward for their guidance! Surely I couldn’t have made it this far without their help.

Labels:

Sunday, February 26, 2006

The underlying connection was closed: An unexpected error occurred on a receive. (Web Service)

We had a web service which was working without any problem for few months and suddenly last week it started to give the above mentioned error. Even though I found some similar threads on the web, nothing helped me to solve the problem.

After few hours of R&D I found a workable solution! Overriding the web service's proxy class fixed the error where I’ve created a new HttpWebRequest.

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
//Get a new HttpWebRequest
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(uri);
webRequest.KeepAlive = false;
return webRequest;
}

Labels: , ,

Where am I Now?

For last couple of months I was very busy with my new job (if you are not aware, currently I’m in Singapore and working for Sonopress Pvt Ltd) and couldn’t concentrate on maintain my blog as well as MCMS Manager.

Now I’m somewhat settled and also playing Lead role ;). I should thank Ananth (my lead) for recognizing me within this short period of time and recommending my name for the above mentioned position!

I’m sure that I’ll start my routine work very soon… (Surely there will be a release on MCMS Manager within couple of weeks!).

Labels:

Saturday, December 31, 2005

Spencer's Article Series on 'ASP.NET 2.0 and MCMS 2002 SP2'

Via Spencer:

With the recent release of Service Pack 2 for MCMS, it is now
possible to take advantage of many ASP.NET 2.0 features within your
MCMS applications. The ASP.NET 2.0 AdRotator control has been enhanced to
allow for programatic population, which makes it much easier to produce a
AdRotator using MCMS Resource Gallery Items.
[Read More]
With the recent release of Service Pack 2 for MCMS, it is now
possible to take advantage of many ASP.NET 2.0 features within your MCMS
applications. One the best new features introduced with ASP.NET 2.0 is Master
Pages, which allow developers to enforce common layout and behaviour across
pages within an application. Whilst at first pass many Master Pages concepts are
similar to those of MCMS, there are a number of benefits to be gained by taking
advantage of Master Pages within MCMS applications.

Labels: ,

Tuesday, December 27, 2005

MCMS Manager 6.0

This version includes,

1. Incremental Export/Import & User Backup/Restore
2. Resource hit Statistics
3. Extended Search

Get the new version from here. For more information check MCMS Manager site. Please don't forget to post your feedbacks here.

Labels: , ,

Friday, December 23, 2005

Modifying Resource Browser to Display Thumbnail for Bitmaps

The Resource Browser (Web Author - Resource Manager) ships with MCMS doesn't provide a thumbnail preview for bmp files. That is acceptable as bmp is not a web image format. But if you are interested in showing a thumbnail for bmp files, it can be done via a customized Resource Manager.

1. Create a class inheriting Microsoft.ContentManagement.WebAuthor.ResourcesBrowse
a) Create a class library.
b) Body of the class -

using System;
using System.Drawing;
using Microsoft.ContentManagement.WebAuthor;
using Microsoft.ContentManagement.Publishing;

namespace MCMS
{
public class CustomResourceBrowser : ResourcesBrowse
{
public CustomResourceBrowser()
{
}

//Create a new method to hide the default DataBindResourceColumnThumbnailUrl
protected new string DataBindResourceColumnThumbnailUrl(object dataitem)
{
Resource resource = (Resource)dataitem;
string url = string.Empty;
IntPtr Missing = IntPtr.Zero;
if(resource.FileExtension.ToLower()=="bmp")
{
using(Image image = Bitmap.FromStream(resource.OpenReadStream()))
{
using(Image thumbImage = image.GetThumbnailImage(32,32,null,Missing))
{
thumbImage.Save(@"PhysicalPath"+resource.Name,System.Drawing.Imaging.ImageFormat.Icon);
url = "http://WebPath/"+resource.Name;
}
}
}
else
{
url = resource.UrlThumbnail;
}
return url;
}
}
}

2. Add the following references
a) using System.Drawing
b) System.Web
c) using Microsoft.ContentManagement.WebAuthor
d) using Microsoft.ContentManagement.Publishing

3. Create a temporary folder with appropriate rights for a web user to write data to that. Have the folder in a saver place as it can be assessed by anyone. Make it as a virtual directory. In the PhysicalPath above class replace it with the path of this directory and WebPath with the virtual directory name.

4. Deploy the dll in the bin folder of your MCMS project.

5. Make a copy of ResourcesBrowse.aspx - its default location "C:\Program Files\Microsoft Content Management
Server\Server\IIS_CMS\WebAuthor\Dialogs\ResourceBrowser\Management\"

6. Open ResourcesBrowse.aspx in notepad and change the Page derivative as bellow
<%@ Page language="c#" Codebehind="ResourcesBrowse.aspx.cs" SmartNavigation="true" AutoEventWireup="false"
Inherits="MCMS.CustomResourceBrowser" %>

This will make thumbnail in the temporary folder for bitmap files, which will be referred by Resource Manager - used to show the preview.

Note: Take precautions before using this method as ResourcesBrowse.aspx may get changed without any notification.

Wednesday, November 30, 2005

MCMS Manager Site Updated

I’ve updated the MCMS Manager site. Hope all of you will like the new look!