Free 1000 mb SVN Repository Hosting at xp-dev.com

Wednesday, 25 March 2009 21:38 by myro

You know best links  always comes from people's blogs... and now is my turn:

http://xp-dev.com

gives you 1000 mb free subversion hosting and project tracking. Give it a try...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Developer Life
Actions:   Bookmark and Share | Permalink | Comments (4) | Comment RSSRSS comment feed

Manually create and attach an SpListItem's Event Handler to a SharePoint 2007 SpList

Tuesday, 24 March 2009 21:53 by myro


Open your Visual Studio and create a new Project as Class Library. Add a reference to "Microsoft.SharePoint.dll", rename Class1.cs to HelloHandler.cs and paste:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

 

namespace Myrocode.Templates

{

    public class HelloHandler : SPItemEventReceiver

    {

        public override void ItemAdding(SPItemEventProperties properties)

        {

            properties.AfterProperties["Title"] = "Hello event handler world !";

        }

    }

}

Build the Assembly, sign it (strong naming) and deploy it in your GAC (Global Assembly Cache - "C:\WINDOWS\assembly"). In the GAC window, get your DLL's Version and Public Key Token's proprieties and write them down. You can use Reflector to simplify this task.
Now you have to attach your custom event handler to a specific list: create a console application project in Visual Studio and paste this snippet:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

 

namespace Myrocode.Templates

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                string siteURL = args[0];

                string listName = args[1];

                using (SPSite site = new SPSite(siteURL))

                {

                    using (SPWeb web = site.OpenWeb())

                    {

                        SPList list = web.Lists[listName];

                        list.EventReceivers.Add(SPEventReceiverType.ItemAdding,

                            "Myrocode.Templates.Handlers, Version=1.0.0.0," +

                            "Culture=neutral," +

                            "PublicKeyToken=78fde53655a71179",

                            "Myrocode.Templates.Handlers.HelloHandler");

                        list.Update();

                        Console.WriteLine("Handlers added correctly!");

                    }

                }

                Console.WriteLine("press any key to exit ...");

                Console.Read();

            }

            catch (Exception ex)

            {

                Console.WriteLine("Error! stack:" + ex.StackTrace);

                Console.WriteLine("Error! message:" + ex.StackTrace);

                Console.WriteLine("press any key to exit ...");

                Console.Read();

            }

        }

    }

Remember to insert your custom properties where you see highlighed code lines.

Credits for this code snippet goes to Peppedotnet.

UPDATE 

More considerations should be done to the update method of a SPListItem.
Let's says that you need to update a SpListItem by adding a new value into the Title field. Here's how the Best Practice indicates should be done:

"Courier New">listItem[listItem.Fields["Title"].InternalName] = “myrocode's handler”;
// IMPORTANT perform the update by disabling the event firing!!
this.DisableEventFiring();
listItem.SystemUpdate(false);
this.EnableEventFiring();

An another tool that can be installed into SharePoint 2007 as a feature is http://www.codeplex.com/speventsmanager, which allows you to manage all the event handlers attached to a SharePoint List directly from your browser.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (2) | Comment RSSRSS comment feed

How to enable SharePoint 2007 to display errors in pages

Tuesday, 24 March 2009 20:24 by myro

If you need to display SharePoint errors during developing, open up your Web.Config file, edit this tags so they look like:

<customErrors mode="Off" />
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10"
     TotalFileDependencies="50" AllowPageLevelTrace="false">
<compilation batch="false" debug="true">

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (2) | Comment RSSRSS comment feed

Recover DLL from GAC

Tuesday, 24 March 2009 20:14 by myro
Let's say you have lost your project's source code, and you have your project compiled and deployed in your GAC. That'a a bad situation... right? What can you do if you want to recover it?
The first thing you need is to retrive you DLL and then disassemble it:
Open cmd, and move to C:\WINDOWS\ASSEMBLY\

C:\WINDOWS\assembly>dir /p

 Volume in drive C has no label.

 Volume Serial Number is 7875-6475

 

 Directory of C:\WINDOWS\assembly

 

29/03/2008  16.21    DIR          GAC

26/04/2008  20.05    DIR          GAC_32

04/05/2008  22.53    DIR          GAC_MSIL

28/03/2008  04.59    DIR          NativeImages1_v1.1.4322

29/03/2008  20.24    DIR          NativeImages_v2.0.50727_32

04/05/2008  22.53    DIR          temp

04/05/2008  22.47    DIR          tmp

              0 File(s)              0 bytes

              7 Dir(s)  25.301.377.024 bytes free

 

C:\WINDOWS\assembly>

As you can see, you can access to all your .NET dll, moving to GAC_MSIL folder. Locate your DLL (you see it as a folder), and export it in this way:

C:\WINDOWS\assembly\GAC_MSIL>cd Microsoft.SharePoint

 

C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint>dir

 Volume in drive C has no label.

 Volume Serial Number is 7875-6475

 

 Directory of C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint

 

26/04/2008  20.04    DIR          .

26/04/2008  20.04    DIR          ..

26/04/2008  20.03    DIR          12.0.0.0__71e9bce111e9429c

              0 File(s)              0 bytes

              3 Dir(s)  25.300.611.072 bytes free

 

C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint>copy 12.0.0.0__71e9bce111e9429c c:\tmp

12.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.dll

        1 file(s) copied.

 

C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint>

In this example i have copied the Microsoft.SharePoint DLL to my c:\tmp folder. Now using Reflector you can easly disassembly it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Developer Life
Actions:   Bookmark and Share | Permalink | Comments (2) | Comment RSSRSS comment feed

Close or Delete WebParts from a page using your browser

Tuesday, 24 March 2009 13:07 by myro

If a Web Parts throws and unhandled exception, and you are unable to close it because you are always redirected to the SharePoint's Error Page, remember that you can manage this situation using your brower:

 http://YourSharePointSite/_layouts/spcontnt.aspx?&url=/Pages/YourPage.aspx

Construct this url and select your WebPart to delete or close.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (2) | Comment RSSRSS comment feed