My SharePoint Blog

Blogs On SharePoint Technologies


Search Site

Recent posts

Recent comments

Tags

Don't show

    Categories


    Disclaimer

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

    © Copyright 2008

    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 (0) | 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 (0) | 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 (0) | 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

    SharePoint Escape Characters

    Ran into a problem when I was writing script to add a new entry to a column (using XML web services). I could not get the column names the same as the were name. Like my "e-mail" column. So for that one I had to type for the id in the script e_x002d_mail.

    Blank space: _x0020_
    Underscore: _x002d_
    Dash: _x0027_

    Here is the Format:

    _x00[the escape code]_


    Char         Code 

    [space]      20
    <            3C
    >            3E
    #            23
    %            25
    {            7B
    }            7D
    |            7C
    \            5C
    ^            5E
    ~            7E
    [            5B
    ]            5D
    `            60
    ;            3B
    /            2F
    ?            3F
    :            3A
    @            40
    =            3D
    &            26
    $            24

     


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

    Create a custom list form for a SharePoint list

    1. Open your site in SharePoint Designer.
    2. Browse to your list and open the 'NewForm.aspx' web form.
    3. Go File -> Save As... and give the form a new name such as 'NewForm2.aspx'.
    4. Hide the default List Form Web Part from the page (do not delete it!!).
      1. Right click the List Form Web Part -> Web Part Properties -> expand Layout -> check Hidden.
    5. Go Insert > SharePoint Controls -> Custom List Form.
    6. In the List or Document Library Form dialog, select the appropriate list, content type and type of form.
    7. Click OK and a new Data Form Web Part is added with controls representing all the fields from the list (in my environment all the controls show "Error Rendering Control" but this does not affect the final result).
    8. In the newly added Data Form Web Part, delete the rows containing fields not to be shown to the user (ensure that fields being removed are not required fields without default values as this would prevent the user from submitting the form).
    9. At this point, you can do other customisation such as rearranging the fields if you wish.
    10. Save the site.

    To make the new form the default form:

        1. Open the site in SharePoint Designer.
        2. Right click the list in the Folder List and select Properties.
        3. Go to the Supporting Files tab.
        4. Use the Browse button to enter the path to your new Edit item form.

    Note: To redirect after the form is submitted, use the following syntax in your misc links that point to the new form...

    http://portal.example.com/Lists/YourList/NewForm2.aspx?Source=http://portal.example.com/redirectpage.htm

     


    Credit:

    http://kalsing.blogspot.com/2006/11/create-custom-list-form-for-sharepoint.html

    http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx 

      

    Problems: ("Invalid page URL"), see these articles:

    http://support.microsoft.com/kb/935504

     

    Gotchas:

    • Do not delete the default List Form Web Part from the page, "Hide" it!  You will get "Invalid page URL" errors if you delete it from your modified newform.aspx.
    • I have discovered that if you create a new item (that uses your modified NewForm.aspx) in a folder of a list, the new item is placed at the root of the list rather than the folder your created the item in.  I have an open Microsoft Support Ticket on this and will update this blog when it resolved.  Update: The have now issued a known bug and put it on their "fix list".  No word on when it will be patched (probably next service release).

     


    Categories: SharePoint
    Posted by Kevin on Wednesday, January 09, 2008 1:43 PM
    Permalink | Comments (10) | Post RSSRSS comment feed

    Cannot get the list schema column property from the SharePoint List

    Cannot get the list schema column property from the SharePoint List

    You will get this popup alert (error message) when you try to export list to a spreadsheet (owssvr.iqy) when the column of a "Date and Time" feild is corrupted. The only fix I have found is to covert the "Date and Time" field to a "Single line of text" then back to a "Date and Time" field. Microsoft, please fix this.


    Categories: SharePoint
    Posted by Kevin on Thursday, October 25, 2007 12:10 PM
    Permalink | Comments (13) | Post RSSRSS comment feed

    Workaround For SharePoint Group Email Limits

    By default when you click Actions --> E-Mail Users, you are limited by characters count in the mailto: property. If you have a large number of users in in a SharePoint Group and you want to email them the action will die without a message. I wrote a bit of Javascript to capture the emails (when the user clicks "E-Mail Users") and copy them to the clipboard if IE or display a div if FF. This way you can start your email client and paste all the addresses in appropriate field. Backup then Edit:

    C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS/people.aspx



    Find (~line # 78):

    function BtnEmailClick(viewId){
        var emails = GetSelectedUsers(viewId, "email", ";");
        if (emails.length == 0)
        {
                alert(noUserEmailSelectedMsg);
                return false;
        }
        emails = "mailto:" + escapeProperly(emails);
        window.location = emails;
        return false;
    }

     

    Replace with:

    /*             POPUP Email Addresses to DIV or Clipboard.               */

    // OLD METHOD
    // function BtnEmailClick(viewId)
    // {
    // var emails = GetSelectedUsers(viewId, "email", ";");
    // if (emails.length == 0)
    // {
    // alert(noUserEmailSelectedMsg);
    // return false;
    // }
    // emails = "mailto:" + escapeProperly(emails);
    // window.location = emails;
    // return false;
    // }


    // NEW METHOD
    function BtnEmailClick(viewId)
    {
        var emails = GetSelectedUsers(viewId, "email", ";");
        if (emails.length == 0)
        {
            alert(noUserEmailSelectedMsg);
            return false;
        }
        emails = escapeProperly(emails);
        emails = unescape(emails);
        // get rid of the anchor mailto:
        emails = emails.replace(emails.substring(emails.indexOf('<'), emails.indexOf('>', emails.indexOf('<')) + 1), "");
        var regEx = /;/g;
        // alert(emails);
        // Post the string to the clipboard if IE.
        if (ClipBoard(emails))
        {
            alert( countNeedles(";", emails) + " email addresses have been copied to your clipboard.");
        } else { // Pop the email in a div.
            emails = emails.replace(regEx, ";\n");
            // make pretty for div
            document.getElementById('popEmailTextArea').innerHTML = unescape(emails);
            popup(document.getElementById('popEmailDiv'));
        }
        return false;
    }
    function popup( obj )
    {
        with( obj.style )
        {
            display = "inline"; position = "relative";
        }
    }
    function unpop( obj )
    {
        obj.style.display = "none";
    }
    function ClipBoard(s)
    {
        if (!document.all)
            return false;
        // IE only
        var holdtext = document.getElementById('holdtext');
        holdtext.innerText = s; Copied = holdtext.createTextRange();
        Copied.execCommand("Copy");
        return true;
    }
    function countNeedles(needle, haystack)
    {
        count = 1;
        pos = haystack.indexOf(needle);
        while ( pos != -1 )
        {
            count++;
            pos = haystack.indexOf(needle, pos+1);
        }
        return count;
    }
    /*       END: POPUP Email Addresses to DIV or Clipboard.        */

     


    Find this:

    <body>

    And paste below:

    <div id="popEmailDiv" style="margin: 10px; display: none">
        <p style="border: 1px solid red; margin: 3px; padding: 3px; color: red; background-color: pink; text-align: center">
            &nbsp;
            <span style="font-weight: bold; font-size: 16px; color: red">Copy and paste email addresses:</span>
        </p>
    </div>

     

     

    Save and test. Summary: Mailto links are limited to 2,083 characters in IE. SharePoint performs a redirect to a "mailto" link which would normally open your email client. If the length of the URL (mailto) is longer than this nothing happens and the redirect is ignored. You can read more about the IE limitation here: http://support.microsoft.com/default.aspx?scid=KB;en-us;q208427

     


    Categories: SharePoint
    Posted by Kevin on Tuesday, October 23, 2007 4:10 PM
    Permalink | Comments (2) | Post RSSRSS comment feed

    SharePoint Elevated Security

    In order for a user to perform tasks on a SharePoint site that require higher permissions than they have, you can use "RunWithElevateedPrivileges" method of the SPSecurity object. The account used is assumed to be the "system account".

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        // CODE TO RUN WITH ELEVATED PRIVILEGES GOES HERE //
        SPSite siteCollection = new SPSite("https://foobar.com");
        SPWeb mySite = siteCollection.AllWebs["tpms/review"];
        mySite.AllowUnsafeUpdates = true;
        SPWeb rootSite = siteCollection.OpenWeb("/");
        SPListItemCollection myList = mySite.Lists["Performance Improvement Notice Tasking"].Items;
        SPListItem updateItem = myList.GetItemById((int)globalIdNumber);
        updateItem["Title"] = "Foobar";
        updateItem.Update();
        mySite.Dispose();
        rootSite.Dispose();
        // END ELEVATED CODE BLOCK //
    });

    This mean no more .credentials auth crap.


    Categories: SharePoint
    Posted by Kevin on Thursday, September 27, 2007 2:09 PM
    Permalink | Comments (0) | Post RSSRSS comment feed