Implement a Message Box to confirm an Asp.Net server control event

Tuesday, 9 June 2009 15:45 by myro

You just need to provide a simple Message box that asks for confirmation when a button is clickked? There are several ways to accomplish this, but if you don't need a complicated solution consider in adding a small javascript to the Asp.Net control on the OnClientClick attribute:

<asp:ImageButton ID="imbdelete"
         OnClientClick="return confirm('Are you sure you want to delete this configuration?');"
         runat="server" CausesValidation="false"
         ImageUrl="~/_layouts/Images/DELETE.GIF" OnClick="imbdelete_click" />

A message box will be prompted when users clicks this Imagebutton, which will raise the postback only if the 'yes' button is pressed. Cool..

Be the first to rate this post

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

Add a new SPField into all SPList' s Content Types programmatically in SharePoint 2007

Tuesday, 9 June 2009 09:53 by myro

If you need to add a new Column (a SPField object) into a SharePoint List programmatically you wil notice that using this snippet

SPList list = SPContext.Current.Site.OpenWeb().Lists["SampleList"];
SPField newField = list.Fields.CreateNewField(SPFieldType.URL.ToString(), "FieldName");
list.Fields.Add(newField);
list.Update();

will only add a new SPField to the default Content Type.
If you need to add this field to all Content Types, consider using the following code snippet:

SPList list = SPContext.Current.Site.OpenWeb().Lists["SampleList"];
SPField newField = list.Fields.CreateNewField(SPFieldType.URL.ToString(), "FieldName");
list.Fields.AddFieldAsXml(newField.SchemaXml, true, SPAddFieldOptions.AddToAllContentTypes);
list.Update();

Now your new SPField named FieldName is visible in all your content types.

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 (1) | Comment RSSRSS comment feed

Custom HttpHandler in SharePoint 2007 using code behind and debug option

Wednesday, 3 June 2009 16:49 by myro

If you need to create an HttpHandler in SharePoint 2007, you need create a source file with the .ashx extension that contains your code and drop it into your \12\TEMPLATE\LAYOUTS\ folder.  Reading this article pubblished from Microsoft at MSDN you can see how to develop an ashx HttpHandler and where it needs to be placed. The bad deal is that this solution is usefull only if you need to create a preatty simple HttpHandler programming using inline code  with no possibilty to debug or test your Http Handler.
My solutiontothis problem is to create a SharePoint 2007 Solution Package that once installed will deploy your assembly into GAC and install the ASHX HttpHandler under the SharePoint's virtual directory called LAYOUTS .
The best way to accomplish this task is:

  1. Create an empty solution using WSPBuilder and configure Visual Studio 2008
  2. Separate you code from the markup: use code behind files and not inline codes
  3. Build your new HttpHandler
  4. Deploy and test it!

To show you how to perform this task correctly, I'll describe each step and provide you the source code of my sample.

1. Create an empty solution using WSPBuilder and configure Visual Studio 2008

Using WSPBuilder, create a new WSPBuilder project and add just a Solution Installer Configuration item as shown in the next picture:

Build the solution and close Visual Studio 2008.
Why are we closing Visual Studio? Because the default project type won't let you add an .ASHX markup file if the project is different from the Web Application type. So, edit the YourProject.csproj file using notepade and make this modification at the top of the file:

 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <PropertyGroup>

replace it with:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <PropertyGroup>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

As you can see this line have been added:

  <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Now you can reopen the project and add any ASP.NET component Smile.

2. Separate you code from the markup: use code behind files and not inline codes

Now you need to instruct your SharePoint Solution to drop the files under the /LAYOUTS/ folder: follow this folder herarchy and add a new HttpHandler with the .ASHX extension:

 

Locate your compiled assembly, drop it into Reflector and get your assembly's full name including the Public Key Token:

 

Now we need to modify the markup page to instruct the run time to load our assembly and the correct class. Edit your ASHX HttpHandler and replace the code with 2 different directives: an assembly import and the main web hander directive. In my case I got something like this

<%@ Assembly Name="SharePointHttpHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23d6ec32decbea39" %>
<%@ WebHandler Language="C#" CodeBehind="SampleHandler.ashx.cs" Class="SharePointHttpHandlers.CustomHttpHandlers.SampleHandler" %>

3. Build your HttpHandler

Ok, now we got the full control of our code. We can edit the code behind and add our sample code:


using System;
using System.Collections.Generic;
using System.Web;
using Microsoft.SharePoint;

namespace SharePointHttpHandlers.CustomHttpHandlers
{
 
    public class SampleHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            context.Response.Write(String.Concat("Hey, your site's url is ",
                SPContext.Current.Site.Url));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

This sample just shows that you are now able to call the SharePoint' s SPContext from your HttpHandler. The handler response with a simple text string that informs you that it works.

4. Deploy and test it

Build your project and create a Deployment Folder using WSPBUILDER.
Now you can deploy your solution using Solution Generator included in WSPBuilder or using the old friend called STSADM.EXE and see if it works well. If it doesn't, debug it! Wink

You can tryout my sample which can be be downloaded here:  SharePointHttpHandlers.rar (485.66 kb)
You will need Visual Studio 2008 and the WSPBuilder extension from codeplex.
Once the SharePoint solution is installed, navigate to:

http://YOURSITE/_layouts/CustomHttpHandlers/SampleHandler.ashx

and you should get a response that writes:  Hey, your site's url is http://YOURSITE

Currently rated 5.0 by 3 people

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

Install OpenOffice 3.1 on Debian Lenny 5.0

Monday, 1 June 2009 12:35 by myro

Installing OpenOffice 3.1 in Debian Lenny 5.0 is simple and you get all your Icons set in Gnome without the need of manually setting up links. What you need to do is:

  • Using Synaptic Manager, remove your old OpenOffice (mine is 2.4) installation
  • Download your .deb packages from http://www.openoffice.org/
        Start downloading OpenOffice.org 3.1.0 for Linux Debian in US English
        (Java runtime, JRE, included for all OS versions except Linux Deb and Mac)
  • Unpack all those .deb that comes from your download into a folder.
  • Open a terminal session into your new folder that contains the debs and type:
      dpkg -i *.deb
  • Move the the subfolder called desktop-integration and retype
      dpkg -i *.deb
  • Now your OpenOffice 3.1 is installed into your system. Go to Application –> Office –> OpenOffice 3.1 Base and configure you workspace

If you see this message once you run OpenOffice:

OpenOffice.org requires a Java runtime environment (JRE) to perform
this task. THe selected JRE is defective. Please select another
version or install a new JRE and select it under Tools - Options -
OpenOffice.org - Java

you should update your Java JRE: install sun-java6-jre using Synaptic Manager and your are done.

Currently rated 5.0 by 1 people

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