My SharePoint Blog

Blogs On SharePoint Technologies


Search Site


My SharePoint Blog recommends any of the following books...


Recent posts

Recent comments

Tags

None

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2009

    Mange Event Handlers (Setup and Usage)

    This post documents the "Manage Event Handlers" (MEH) project from Codeplex.  The MEH tool allows you rapid deployment of event handlers.  Additionally you can assign the handler to any Site, List, or Content Type.  Note: this works for WSS 3.0 and MOSS 2007.

    The .wsp file is located here:

    http://www.codeplex.com/SPSCustomAdmin/Release/ProjectReleases.aspx?ReleaseId=3024

    To install the MEH tool from command line:

    stsadm -o addsolution -filename MOSS.CustomAdminPages.EventHandlers.Deploy.wsp

    stsadm -o execadmsvcjobs

    stsadm -o deploysolution -name MOSS.CustomAdminPages.EventHandlers.Deploy.wsp -local -force -allowGacDeployment -allowCasPolicies 

    stsadm -o execadmsvcjobs

    stsadm -o activatefeature -name ManageEventHandlers -url http://foobar.com

    stsadm -o execadmsvcjobs 

     

    Now you should see your MEH tool in the Site Setting Page:


     
     
      
     
    Now build the event handler as you normally would and drop the compiled dll in the GAC.  
     
    After the assembly is in the GAC, you can now add it to your SharePoint site and assign it to a Site, List, or Content Type using the "Add" page of the MEH tool:
     
     

     

    You can assign the same event handler to many different Site, Lists, or Content types.  You need only click "Add" and set the properties!! 

    Awesome! 

    Show the AfterProperties snippet:

    protected void showAfterProperties(SPItemEventProperties properties)

            { 

                using (SPWeb web = properties.OpenWeb())

                {

                    String strTemp = "";  

                    /*get the current list*/

                    SPList list = web.Lists[properties.ListId];

                    string columnName = "";

                    foreach (SPField fld in list.Fields)

                    {

                        columnName = fld.InternalName;


                        if (properties.AfterProperties[columnName] != null)

                            strTemp += "\n" + columnName + ": " + properties.AfterProperties[columnName].ToString();

                    }

                    properties.ErrorMessage += strTemp;

                    properties.Cancel = true;

                }

            } 

     

    Additional Notes:

    http://jpy-tech.com/post/2009/02/05/Sharepoint-Unique-Column-(PK)-Using-event-handler.aspx 

    http://www.sharepointblogs.com/toth/archive/2008/06/06/workarounds-for-itemadding-itemadded-event-handlers.aspx

    http://www.iterasi.net/openviewer.aspx?sqrlitid=-lt435um10as0obb4eq48q

     


    Posted by Kevin on Thursday, June 04, 2009 2:36 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    Call Your JavaScript Function When Page (body) Is Loaded

    In a SharePoint enviroment, the proper way to execute client side code when the page/body is loaded is to use the following function...

      

    _spBodyOnLoadFunctionNames.push("myBodyLoadedFunctionName");


    Posted by Kevin on Tuesday, March 31, 2009 4:29 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    Configure Search On MOSS 2007 (Microsoft Office SharePoint Server)

    The following procedures step you through the process of configuring Office SharePoint Server 2007 search services, creating a Web application for the SSP, creating the SSP, and configuring indexing settings.

     

    Start and configure the Search service

    1. On the SharePoint Central Administration home page, click the Operations tab on the top navigation bar.
    2. On the Operations page, in Topology and Services, click Servers in farm.
    3. On the Servers in Farm page, click the server on which you want to configure the search service.
    4. Click Start next to Office SharePoint Server Search.
    5. On the Office SharePoint Server Search Settings page, in the Query and Indexing section, make sure that the Use this server for indexing content and Use this server for serving search queries check boxes are selected.
    6. In the Default Catalog Location section, type a path to a physical folder to store the index files, or use the default location that is specified.
    7. In the Contact E-Mail Address section, specify a valid e-mail address.
    8. In the Service Account section, click Configurable, and in User name and Password, type the user name and password for the user account under which you want the Search service to run. The user account must be a member of the Administrators group on the computer that is running the Search service. If you want to use the principle of least privilege and select a unique user account that does not have administrative rights on your front-end servers or on your back-end database servers, see the Known Issues/Readme for Office SharePoint Server 2007 Beta 2. The user name must be in the format DOMAIN\username.
    9. In the Web Front End And Crawling section, do one of the following:
      • If you are configuring the search service on a server that provides Web services and renders Web content, click No dedicated Web front-end computer for crawling
      • If you are configuring the search service on a server that is a standalone search server that does not provide Web services and render Web content, click Use a dedicated web front end computer for crawling, and then, in Select a web front end computer, click the computer you want to use for crawling.
    10. Click Start.
    Start the Windows SharePoint Services Web Application service

    You must start the Windows SharePoint Services Web Application service on every computer that you want to act as a Web server and was set up using the Complete option during Setup. This service is started by default on servers that were set up using the Web Front End option. To enhance security, you can leave this service turned off on application servers that do not provide Web content to client computers. Also, you do not need to turn this service on to use SharePoint Central Administration on a server.

    1. On the SharePoint Central Administration home page, click the Operations tab on the top navigation bar.
    2. On the Operations page, in Topology and Services, click Servers in farm.
    3. On the Servers in Farm page, click the server on which you want to start the Windows SharePoint Services Web Application service.
    4. Click Start next to Window SharePoint Services Web Application.
    Create the Shared Services Provider
    1. On the SharePoint Central Administration home page, click the Application Management tab on the top navigation bar.
    2. On the Application Management page, in the Office SharePoint Server Shared Services section, click Create or configure this farm's shared services.
    3. On the Manage this Farm's Shared Services page, click New SSPImportant: If you have not created a Web application for the SSP administration site, you need to create one before you create the SSP. If you have already created a Web application for the SSP administration site, skip to step 14.
    4. On the New Shared Services Provider page, click Create a new Web application.
    5. On the Create New Web Application page, in the IIS Web Site section, click Create a new IIS web site, and do not modify the default settings in this section.
    6. In the Security Configuration section, under Authentication provider, select the appropriate option for your environment, and do not modify the default settings in the remainder of this section.
    7. In the Load Balanced URL section, do not modify the default settings.
    8. In the Application Pool section, click Create new application pool.
    9. In Application pool name, enter the name of your application pool or use the default name.
    10. Click Configurable, and in User name and Password, type the user name and password for the user account under which you want the application pool to run. The user account does not have to be a member of any particular security group. It is recommended that you use the principle of least privilege and select a unique user account that does not have administrative rights on your front-end servers or on your back-end database servers. You can use the user account that you specified as the Office SharePoint Server 2007 service account; however, if that user account is a member of a security group that has administrative rights on your front-end servers or your back-end database servers, you will not be following the principle of least privilege. The user name must be in the format DOMAIN\username.
    11. In the Database Name and Authentication section, verify the database information and make sure that Windows Authentication (recommended)is selected.
    12. In the Search Server section, do not modify the default settings.
    13. Click OK. Upon successful creation of the Web application, the New Shared Services Provider page appears.
    14. In the SSP Name section, in Web Application, select the Web application that you created for the SSP, and do not modify any of the default settings in this section.
    15. In the My Site Location section, do not modify any of the default settings.
    16. In the SSP Service Credentials section, in User name and Password, type the user name and password for the user account under which you want the SSP to run. The user account does not have to be a member of any particular security group. It is recommended that you use the principle of least privilege and select a unique user account that does not have administrative rights on your front-end servers or on your back-end database servers. You can use the user account that you specified as the Office SharePoint Server 2007 service account; however, if that user account is a member of a security group that has administrative rights on your front-end servers or your back-end database servers, you will not be following the principle of least privilege. The user name must be in the format DOMAIN\username.
    17. In the SSP Database section, you can either accept the default settings (recommended), or specify your own settings for the database server, the database name, or the SQL authentication credentials.
    18. In the Search Database section, you can either accept the default settings (recommended), or specify your own settings for the search database server, the database name, or the SQL Server authentication credentials.
    19. In the Index Server section, in Index Server, click the server on which you configured the Search service.  Note: If there is no index server listed in the Index Server section, then no server in your farm has been assigned the index server role. To assign the index server role to a server in your farm, follow the instructions in the "Configure the Search service" section earlier in this topic.
    20. In the SSL for Web Services section, click No.
    21. Click OK. Upon successful creation of the SSP, the Success page appears.
    22. On the Success page, click OK to return to the Manage this Farm's Core Services page.
    Configure indexing settings
    1. On the SharePoint Central Administration home page, click the Application Management tab on the navigation bar.
    2. On the Application Management page, in the Office SharePoint Server Shared Services section, click Create or configure this farm's shared services.
    3. On the Manage this Farm's Shared Services page, click SharedServices1.
    4. On the Shared Services Administration page, in Search, click Search Settings.
    5. On the Configure Search Settings page, in the Crawl Settings section, click Default content access account.
    6. In the Default content access account section, in Account, Password, and Confirm Password, type the user name and password for the user account that you want to use to crawl content on your sites. This account must be a domain user account. It is recommended that you use the principle of least privilege and select a unique user account that cannot modify content and does not have administrative rights on your front-end servers or on your back-end database servers. You can use the user account that you specified as the Office SharePoint Server 2007 service account; however, if that user account is a member of a security group that has administrative rights on your front-end servers or your back-end database servers, you will not be following the principle of least privilege. The user account that you specify will be added to the Web application Full Read policy for your farm. The user name must be in the format DOMAIN\username.
    7. Click OK.
    8. In the Crawl Settings section, click Content sources.
    9. On the Manage Content Sources page, click Local Office SharePoint Server sites.
    10. On the Edit Content Source page, in the Crawl Schedules section, under Full Crawl, click Create schedule.
    11. In the Manage Schedules dialog box, configure schedule settings for full crawls of your content, and then click OK.
    12. In the Crawl Schedules section, under Incremental Crawl, click Create schedule.
    13. In the Manage Schedules dialog box, configure schedule settings for incremental crawls of your content, and then click OK.
    14. In the Start Full Crawl section, select the Start full crawl of this content source check box, and then click OK.


    You are done!

     

    More Info in this fantastic article.

     

     

     

     


    Categories: SharePoint
    Posted by Kevin on Wednesday, October 08, 2008 10:25 AM
    Permalink | Comments (4) | Post RSSRSS comment feed

    How To Iterate SharePoint Attachments Using The API

    Looking for a way to iterate a SharePoint list item (SPListItem) for all attachments and render them on your page?  Here is a nice example....

    private String x_renderAttachmentData(SPListItem listItem)
    {
        String strAttachmentData = String.Empty;

        try
        {

            if (listItem.Attachments.Count > 0)
            {

                foreach (string fileName in listItem.Attachments)
                {
                    SPFile spFile = listItem.ParentList.ParentWeb.GetFile(listItem.Attachments.UrlPrefix + fileName);
                    int fileSize = (int)spFile.Length / 1000;
                    strAttachmentData += "<div class='attachment'>"
                                       + "<img src='_layouts/images/" + spFile.IconUrl + "'> "
                                       + "<a target='_blank' href='" + URL_ROOT + "/" + spFile.Url + "'>"
                                       + spFile.Name + "</a> &nbsp; (" + fileSize + " KB)"
                                       + "<div class='hr'></div>Attachment version: " + spFile.UIVersionLabel
                                       + "<br/>Created at " + spFile.TimeCreated.ToString() + " by "
                                       + spFile.Author.ToString().Substring(spFile.Author.ToString().IndexOf('\\') + 1)
                                       + "<br/>Last modified at " + spFile.TimeLastModified.ToString() + " by "
                                       + spFile.ModifiedBy.ToString().Substring(spFile.ModifiedBy.ToString().IndexOf('\\') + 1)
                                       + "</div><div style='clear:left;'></div>";  // just call me a css genius.
                   
                }
            }
            return strAttachmentData;

        }
        catch (Exception exp)
        {
            // handle exp.
        }
    }

     

     

    Output for this function looks like this... 

     

     

    Here is the css if you are interested....

    .attachment
    {
     color:#999999;
     font-size:9px;
     margin-bottom:0px;
     float:left;
    }
    .attachment img{margin-bottom:-2px;}
    .attachment .hr
    {
     border-top:1px solid #bbbbbb;
     margin-top:2px;
    }
    .attachment a:link,
    .attachment a:visited,
    .attachment a:hover
    {
     font-size:14px;
     line-height:18px;
    }

     

     


    Categories: SharePoint
    Posted by Kevin on Friday, September 26, 2008 3:07 PM
    Permalink | Comments (2) | Post RSSRSS comment feed

    SharePoint Convert UTC To Local Time

    For example, the LastItemModifiedDate property of a SPList is not local time, it is UTC.  So just use the SPWeb object to convert it to local time.

    DateTime myDT = mySPWeb.RegionalSettings.TimeZone.UTCToLocalTime(mySPList.LastItemModifiedDate)


    Categories: SharePoint
    Posted by Kevin on Friday, May 09, 2008 2:00 PM
    Permalink | Comments (1) | Post RSSRSS comment feed

    DevConnection 2008 SharePoint

    Boss sent me to DevConnecitons again and it was great!

    Here are my notes for the SharePoint classes I sat in on.

     

    • Pre Conference Work shop: SharePoint Workflows HPR201 by Rober Bogue.
      • SharePoint Designer workflows pros/cons:
        • Not truely "portable" becuase of list GUID's in XAML and must be associated with an item.
        • No code needed.
        • GUI based.
      • Visual Studio workflows pros/cons:
        • Complete control.
        • Require strong development skills.
        • Requires more time to develop.
      • SharePoint Designer Workflows can be extened with Visual Studio.
      • Required for Visual Studio Dev:
        • Visual Studio Extensions for Workflow Foundation.
        • VSeWSS
      • Workflow Types:
        • Sequential (think SharePoint Designer workflows)
        • State Machine.
      • Can run a WorkFlow on a content type.
      • Note: Pauses in SP Designer WorkFlows are averaged out to ~5 minutes due to the SP timer trigger interval.
      • WorkFlow DLL must be deployed to the GAC.
      • When building a VSworkflow, it becomes a workflow type availible in the List settings -> Workflow.  YEA!
      • Set a fault handler to catch all faults in your VS Workflow type (see Robert Bogue's Blog).
      • Tip: Restart WSS timer every 4 hours due to memory leaks.
      • Errors are logged here = 12\logs\.
      • Get log viewer utiltiy from CodePlex here.
      • .wsp files is a special cab file.
      • Brackets for GUID's are allowed and only allowed in the ContentType.xml.  It is the only place in sharepoint.
      • DisplaceOnUpgrage="TRUE" required inContentTypes.xml.  This is becuase any new changes will not upgrade by default.
      • Included in this zip is a nice LDAP class.  200804SPConn-Workflow.zip (4.28 mb)
      • Here is a nice web debugging utitlity (HTTP debugger proxy): http://www.fiddlertool.com/fiddler/
    • More to come soon.



    Categories: SharePoint
    Posted by Kevin on Tuesday, April 29, 2008 3:01 PM
    Permalink | Comments (1) | Post RSSRSS comment feed

    Authenticating to SharePoint SSL Web serivce that requires client certificate

    If you are trying to consume a Sharepoint web service - from a Windows Application - on a server that is configured for both SSL and Require Client Certificate, you need to do the following:

    1. First, export the client certifiate to a file following the directions in the section titled: "Step 1: Export the Client Certificate to a File" at this link: http://msdn2.microsoft.com/en-us/library/aa302408.aspx.
    2. Next you need to tell the web service to use that certificate like this: lists.ClientCertificates.Add(X509Certificate.CreateFromCertFile("C:\file_where_certificate_is_stored_from_above_step");
    3. Finally (and this is the part that Microsoft left out of their instructions) you need to authenticate to the web service using ONE of the following methods:
      • lists.Credentials = CredentialCache.DefaultNetworkCredentials; <-- This uses the credentials of the logged on user.
      • CredentialCache cache = new System.Net.CredentialCache(); cache.Add(new Uri(lists.Url), "Basic", new NetworkCredential(UserID, Password, Domain)); lists.Credentials = cache;

     

     


    Categories: SharePoint
    Posted by John on Friday, April 18, 2008 9:15 AM
    Permalink | Comments (1) | Post RSSRSS comment feed

    SharePoint issues with AllowPartiallyTrustedCallers

    PROBLEM: If you are trying to deploy a webpart from a Visual Studio solution and get this error... 

    Unable to add selected web part(s).

    Assemblies that implement ASP.NET Web Parts and are installed into a partially trusted location, such as the bin directory, must be compiled with the AllowPartiallyTrustedCallers set for import to succeed.

     

    FIX: Add the following to your AssemblyInfo.cs and recompile.

    using System.Runtime.InteropServices; 

    [assembly: AllowPartiallyTrustedCallers] 

     


    Posted by Kevin on Thursday, March 13, 2008 3:18 PM
    Permalink | Comments (1) | Post RSSRSS comment feed

    Running Code Blocks In Your SharePoint ASPX Pages.

    You may see this error:

    An error occurred during the processing of /test.aspx. Code blocks are not allowed in this file.

    Reason:  SharePoint does not allow server side code to execute in aspx pages contained in the SharePoint site.

    Fix:  Edit the web.config (I.E. C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config) file:

    <PageParserPaths>
            <!-- To allow a single file: -->
            <PageParserPath VirtualPath="/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />
            <!-- To allow global: -->
            <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" />
            <!-- To allow global within a subsite: -->
            <PageParserPath VirtualPath="/websitefoobar/*" CompilationMode="Always" AllowServerSideScript="true" />
    </PageParserPaths>

    Categories: SharePoint
    Posted by Kevin on Tuesday, January 29, 2008 12:04 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    SharePoint Lists Filter Keywords and Expressions In Views

    [Today] The current date.

    [Me] Current User of the site.

    [Modified] Date item was last modified.

     

    Filter Expression Examples: 

    [Modified]+7  A week after the last modification.

    DATE(YEAR(Modified),MONTH(Modified),DAY(Modified)+5)  5 Days after the last modification. 

     

     
    Formulas and Functions:

    http://office.microsoft.com/en-us/sharepointtechnology/CH100650061033.aspx


    Categories: SharePoint
    Posted by Kevin on Tuesday, January 29, 2008 10:30 AM
    Permalink | Comments (0) | Post RSSRSS comment feed