CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

Archive for the ‘Office 12’ Category

SharePoint Designer Training

Posted by Clayton James on October 14, 2009

I am currently up in the sugar capital of Australia, Mackay delivering a 3 day SharePoint designer training course.

Lots of cool things learned:

  • Embedding/displaying videos from a document library in a web page
  • Branding: Custom master page design, CSS and overriding core.css
  • Integrate Twitter into your site
  • DataView Web Part: integration with databases, web services and rss (and sharepoint rollups)
  • IE Developer Toolbar is your best friend

And why are those Fab 40 templates so crap!

Posted in MOSS 2007, Presentaitons | Leave a Comment »

Security Trim "View All Site Content"

Posted by Clayton James on July 28, 2009

I have been asked this a few times. How can I remove the View All Site Content link for certain users?

The View All Site Content link can be a great navigational link or a problematic link that confuses end users.
image

The default security setting for this SPLinkButton is set to be displayed to everyone…and when I say everyone I mean everyone…viewers and even anonymous users. This is found in the master page in your site.

  1. Open up the master page in SharePoint designer
  2. Place the page into split view
  3. Click the View All Site Content link and in you code window you should see the following

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ViewFormPages”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>
</SharePoint:SPSecurityTrimmedControl>

 

Thankfully we can easily upgrade the security to different security level. For example, if we change the PermissionsString=”ManageWeb” then only users who have this permission level (site admins) will see the View All Site Content link.

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>
</SharePoint:SPSecurityTrimmedControl>

 

There are a number of different permission levels that you can view here.

The SharePoint:SecurityTrimmedControl is a handy control that can be used in many locations. For example, wrap it around the Site Actions control for custom and you remove this control based on security.

Posted in WSS 3.0 | 15 Comments »

Add .Net User Controls to SharePoint

Posted by Clayton James on May 25, 2009

I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.

  1. I have a Graphical User Interface
  2. I have a separate project to build and test outside of SharePoint
  3. I can easily update and view my project html and binary code

Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.

  1. Create a VS2008 web project
  2. In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
  3. In your VS2008 project create some user controls and test that they function
  4. In VS2008 project properties under the Build Events¬†tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to¬†your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008¬†project. I had problems when I put the VS2008 project .dll into the¬†GAC…it only worked when I put it into the SharePoint’s web sites bin directory
  5. Update your master page with CSS references if your VS2008 project contains a style sheet.
  6. In SPD in your Page Layout add a Register directive to register your user control
    “<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
    OR
    Update the SharePoint web site web.config file
    <pages>
      <controls>
    ¬†¬†¬†¬†¬†¬†¬† <add¬†src=”~/UI/UserControls/MyAttributes.ascx”¬†tagPrefix=”uc1″ tagName=”MyAttributes”/>
    ¬†¬†¬†¬†¬†¬†¬† <add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
        </controls>
    </pages>
  7. Add the User Control to the Page Layout
    <uc1:JobGoals ID=”JobGoals1″ runat=”server” />
  8. Update the SharePoinnt web sites web.config file
    <SafeControl Src=”~/UI/*”¬† IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
  9. Restart IIS, navigate to a page that uses the page layout and you should see your User Control

Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.

  1. .ascx changes:                modify, save in VS2008 and refresh sharepoint browser
  2. .ascx.cs changes:          modify, save, build  in VS2008 and refresh sharepoint browser

Posted in .NET 2.0, .Net 3.0, WSS 3.0 | 4 Comments »

User Group Presentation – Content Query Web Part – Part 2

Posted by Clayton James on May 20, 2009

I completed my Part 2 presentation on the CQWP today. I thought that the rain may have kept the numbers down so it was great to see a good turn out.

Topic Covered:

  • How and where best to use – plan ahead
  • Displaying extra columns in result set
  • Modifying the ItemStyle.xsl and .webpart files
  • XSLT
  • Tips and tricks – (thanks Tim for the select=.) tip
  • Subclassing using Visual Studio
  • Deployment

 

I always need more time presenting at user groups.

Slide deck and demos will be uploaded to the BSPUG site soon.

Posted in MOSS 2007, Presentaitons | 1 Comment »

SharePoint Authentication: FireFoxs works but IE doesn’t

Posted by Clayton James on May 20, 2009

I was having a great deal of pain on a new SharePoint development server recently. Environment = Windows 2008, IE7.

Situation

  1. Create a SharePoint web application with a host header on port 80. Create a site collection
  2. Update host file (or DNS) with new host header entry
  3. In IE make sure the web application is in the Intranet Zone
  4. Open up browser in IE navigate to site using host header and the authentication dialog login is displayed.
  5. Enter my credentials 3 times and receive a 401.1 and an entry in the Security Event log
  6. If I open FireFox and browse to the web site the authentication dialog is displayed
  7. I enter my credentials and I can log in fine
    Note: To get rid of the authentication prompt in FireFox
    1. Open FireFox and in the address type about:config
    2. Find the entry network.automatic-ntlm-auth.trusted-uris
    3. Set the Key’s value to a comma seperated list of trusted URIs i.e your host header
  8. So FireFox is fine but IE is having issues

 

Solution

I finally stumbled across a blog article from Brian Farnhill and Ishai Sagi that lead me to the solution.

You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or IIS 6
http://support.microsoft.com/default.aspx/kb/896861

In my case I am using IE 7 and while the Solution/Workaround discusses two separate methods and states that method one is preferred, I could only fix my issue upon completing method 2

Posted in MOSS 2007, Office 12, WSS 3.0 | 3 Comments »

Importing AD Employee Photos into SharePoint User Profiles

Posted by Clayton James on May 8, 2009

I was recently asked to provide a process for importing Employee pictures into SharePoint so they would show up in search results and various OOTB web parts. This particular client has MOSS but doesn’t use My Sites.

This post by Henry initially helped me out.

They didn’t want the individual users to have the abilty to upload their own photo’s or modify them in any way, this was to be managed by IT.

  1. Create a Picture Library in your Intranet. This will store the photo’s for each employee. When storing employee photo’s chose the filename carefully if you want to populate the AD using scripts. I use something like cjames.jpg which is a correlation to the users account name.
  2. In Active Directory choose an AD property that will be mapped to your SharePoint User Profile Property. In my case I selected the extensionAttribute1 field that is located in the ExchangedAdvanced tab ((note this field may not show up if the Exchange Mgt Console hasn’t been installed)
  3. Populate this field with the URL to the employee’s photo that is in the Picture Library e.g http://sitename/ProfilePhotos/CJames.jpg (look below for a script example)
  4. In SharePoint SSP click the User Profiles and Properties link
  5. Click the View Profile Properties under the heading User Profile Properties
  6. Find the Picture property and select the Edit menu item
  7. Make note of the Usage: Number of profiles using this property. This should increase after we complete a full import
  8. At the bottom of the screen make sure Master Connection is selected and in the Datasource field to map select extensionAttribute1 (note: this field may not show up if the Exchange Mgt Console hasn’t been installed)
  9. Click Ok
  10. Complete a StartFull Import
  11. Once the full import is complete go back into the the Picture property and again check the Usage:Number of profiles that use this property. This should now contain some values.
  12. Verify this by viewing an Employee’s profile and the Picture property

Some things I had issues with:

  • Make sure your Import Connection service account has “Manage User Profile” permissions
  • May need to execute a Full Search crawl once photos are uploaded in the Picture Library

I also wrote a script to populate the AD extensionAttribute1 field as there were over 1000 employee’s and no one put their hand up for this job. The import thing here was for employee photo images to have a one to one mapping with their login account name (samaccountname). The person who runs this script also needs certain permissions in AD to update AD accounts. I would initially comment out the¬†On Error Resume Next so you see if your account has enough privleges or not.

The script is very limited but hopefully it may provide some insight.

‘On Error Resume Next
Set objParent = GetObject(“LDAP://OU=Users,OU=Austraila,OU=Offices,OU=AU,DC=domain,DC=local“)
objparent.Filter = Array(“user”)
for each objUser in objParent
¬† Wscript.Echo “Modifying ” & objUser.Get(“samaccountname”)¬†
¬† objUser.put “extensionAttribute1”, “http://sitename/ProfilePhotos/” & objUser.Get(“samaccountname”) & “.jpg”
  objuser.Setinfo   
next

Wscript.Echo “End”

Now, IT¬†are responsible whenever they create a new account they must also populate the extensionAttribute1 field with the URL of the picture library and the employee’s picture filename will always be their account name.

Posted in MOSS 2007, Office 12 | 207 Comments »

Sign in as a Different User

Posted by Clayton James on May 7, 2009

This little feature has caused myself so many problems for different clients. Some of the main issues I have come across include:

  • Still runs .Net code under the person who has logged into the computer
  • Creates authentication issues for end users when trying to open an Intranet bowser. Have to remove their user profiles to fix

I recommend to anyone now to¬†find the IExplore.exe (right click your shortcut and select Properties, then click the¬†¬†“Find Target” button), right click¬†and¬†select the¬†“run as”. Enter the credentials of the user you wish to log in as.

This still won’t run .Net code under the¬†new credentials you have entered but I have not come across any authentication issues using this approach so far.

Posted in WSS 3.0 | 1 Comment »

Non-Admins View Site Usage Reports

Posted by Clayton James on May 5, 2009

How to get non-admins to view your site collection and site usage reports

Site Collection Admins or user will Full Control can view Site Collection and Site Usage Reports.  So if you want other users to access these reports you can do the following:

  1. Create a custom site permission level and select the “View Usage Data” check box
    Note: this will also select the “View Pages” permission
  2. Create a new Group called something like “Usage Report Viewers” and assign the permission level you created above to the group
  3. Add the people you want to view the reports
  4. Provide the users with links to the report pages
    1/ http://sitecollection/_layouts/SpUsageSite.aspx Рview site collection reports
    2/ http://sitecollection/_layouts/SpUsageWeb.aspx Рview site reports

Use a web part to display the links and above and audience targeting so only the users in the SharePoint group “Usage Report Viewers” see the web part.

Posted in WSS 3.0 | 6 Comments »

Tech.Ed 2008…that’s a wrap

Posted by Clayton James on September 7, 2008

It has been a big week!

I taught a two day pre-conference course for Microsoft on building Internet sites using the SharePoint platform. We covered many areas including:

  • Architecture
  • Custom master pages, page layouts, css
  • Web parts
  • Optimisiation. IIS compression, caching, loading core.js
  • Content deployment
  • Extending publishing sites

It was a great couple of days that was also extremely busy with 34 students.

I went to a lot of SharePoint sessions this year and met some leaders in the industry. Todd Bleeker, Ishai Sagi, Ben Curry, Andrew Coates, Joel Olsen .

Todd pioneered SharePoint development by writing the first WSS 3.0 development book (it is my favourite SharePoint development book).

I also went to a Silverlight session. It seemed more a designers sessions than a coders session and I wasn’t really impressed. It demonstrated the expression suite. It is only beta 2 but stills seems lacking in VS integration (I don’t want another product to develop applications) and controls. Lots of hand coding in xaml.

And guess what happened this year…..we didn’t have to wait and get scanned in before sessions. That’s right…we had RFID chips which scanned us into rooms automatically. Great work was completed by the Breeze team in coordinating and brining this to reality.

Posted in .NET 2.0, MOSS 2007, WSS 3.0 | 1 Comment »

Error – Custom EditForm.aspx with EventHandler

Posted by Clayton James on August 27, 2008

I have been pulling my hair out for the last couple of hours trying everything possible. Thankfully came across this hotfix.

Scenario

  • Creat a custom edit form in SharePoint designer
  • Create an event handler for ItemUpdating in Visual Studio and bind it to the list that has the custom edit form
  • Whenever you try to update a list item you receive the following error message
    “The data source control failed to execute the update command”

¬†“This hotfix fixes the following issue that was not previously documented in a Microsoft Knowledge Base article:

You design a project that contains a Windows SharePoint Service 3.0 list. The list uses a custom list form. Additionally, you design the project to display an error message when an ItemUpdating event is triggered. However, when you update an item in the list, the custom error message is not displayed. Instead, you receive the following error message from Windows SharePoint Service 3.0:

The data source control failed to execute the update command”

I haven’t applied it yet but it is exactly my problem.
http://support.microsoft.com/kb/949749

UPDATE: 12/Sep/2008
This hotfix has fixed my problem. I am very happy ūüôā

Posted in WSS 3.0 | 9 Comments »

Enable Content Scheduling – Collaboration Portal

Posted by Clayton James on August 13, 2008

The Collaboration Portal template doesn’t allow for content scheduling by default. You have to complete a few actions first.

If you are using the Collaboration  Portal and want to use the scheduling feature to publish content from a start date and remove it when it hits an end date then you will need to complete the following.

  1. In the Pages document library settings click on Versioning settings, then check the Require content approval for submitted items, and make sure the Create major and minor versions radio button is selected (needed to place content into draft state when expired).
  2. Click the Manage Item Scheduling link and check Enable scheduling of items in this list

A couple of things to be aware of:

  • When an item is removed as it has passed its scheduled end date then it places the item into draft mode.
  • Filtering (Web Parts, Views) on Scheduling Start Date and Scheduling End Date doesn’t seem to work
  • You may find adding your own Start Date and End Date provides filtering functionality in Web Parts and Views and you can also run a workflow against these columns for archiving.

Posted in MOSS 2007 | 6 Comments »

New U2U CAML builder

Posted by Clayton James on August 11, 2008

Kudos to Karine from U2U. She has come up with a new version for building CAML queries.

I have used the previous version of the U2U CAML Builder and have recommended it to others. This is the only way I chose to build CAML queries.

Download and let CAML become your friend ūüėČ

View the great new features and download here.

Posted in MOSS 2007, WSS 3.0 | Leave a Comment »

Site Columns Gallery Error

Posted by Clayton James on August 4, 2008

I was receiving this error the other day when trying to access the Site Column Gallery.

Object reference not set to an instance of an object.   at Microsoft.SharePoint.ApplicationPages.FieldListRenderer.Render(HtmlTextWriter output)
¬†¬† at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) ……..

It turns out that if you create a site column using the object model it capitalises SITES in the url.

The root problem was with the request Url we used to open a SPSite/SPWeb.  It turns out that the request Url you use to construct a SPSite is *case sensitive* to the URL the way it is specified in SharePoint when it comes to creating SPField objects programmatically.  I know that seems a little hard to believe but we ended up driving this bug through PSS and after getting our Content DB demonstrating the problem into MS hands they walked through their code and identified the problem in the code behind mngfield.aspx and a requirement that any fields created via WSS must have been done so through an SPSite/SPWeb with case that exactly matches the target site.

One additional thing we found through this two month adventure researching this bug, you can see the fields in a root site collection via mngfield.aspx *if* you view the Site Column gallery from a sub site of the site collection where mngfield.aspx is returning the Unknown Error/Null reference exception.

Here is how you can determine if the fields you created have the appropriate case-sensitive scope.

1. Create a sub-site under the site collection.

2. From that sub-site, select Site Actions -> Site Settings -> under Galleries -> Site columns

3. The mngfield.aspx page should display, and you will see all site columns from the parent site collection.

Note that the Source column on this page is a hyperlink to the site collection mngfied.aspx.¬† If you click this link you’ll be taken to the familiar Unknown Error.

4 Look for any site columns that your code added to the site collection.¬† Pay particular attention to the letter-case of the Source hyperlink Url.¬† If you’re hitting the same issue we found, you’ll note that the hyperlink Url case does not match the case of the actual site.

Basically there is a line of code in the code behind mngfield.aspx that does a check something along the lines of “field.Scope == web.ServerRelativeUrl”.¬† The ‘==’ op was a poor choice as it doesn’t handle mixed cases.

Once a Site Column has been created via WSS using a SPWeb instance that was constructed with mis-matched case that column is broken, it cannot be fixed.¬† You’ll have to delete it and recreate under a SPWeb that was constructed either a) with a request Url of appropriate case or b) the safer option is to construct SPWeb/SPSite instance using their GUID constructor since that forces a Url lookup which will always be accurate.

So to fix this you need to navigate to the fieldedit.aspx page in the layouts directory, pass in the field name and then can you can delete the problematic site column.
e.g.  http://moss/sites/companyxyz/_layouts/fldedit.aspx?field=tt

Posted in MOSS 2007, WSS 3.0 | 9 Comments »

CustomAction & UrlAction

Posted by Clayton James on July 30, 2008

Update:
Some more CustomAction elements I have come across include:
– Rights: You can set a Rights property so only people with these rights can view the Custom Action
      Rights=”ManagePermissions”
      You can also remove existing CustomActions based on rights
– RegistrationType and RegistrationId: I have previously set these to lists, however you can even set them to file types. So only files with a .html extension will see this custom action in the ECB menu
     RegistrationType=”FileType”
     RegistrationId=”html”

 

Here is some great information from Jan Tielens Blog.
http://weblogs.asp.net/jan/archive/2007/09/05/using-the-current-page-url-in-the-urlaction-of-a-sharepoint-feature.aspx

I am including the content as I always reference it.

MSDN documentation also.
http://msdn.microsoft.com/en-us/library/ms473643.aspx

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
    <CustomAction
        Id=”{6FCB0F81-2105-4d9f-96BF-C48A19B8E439}”
        Title=”My Link”
        Location=”Microsoft.SharePoint.StandardMenu”
        GroupId=”SettingsMenu”>
        <UrlAction Url=”_layouts/mypage.aspx”/>
    </CustomAction>
</Elements>

If you build some functionality in the mypage.aspx, in many scenarios this page will need to know from which list the link originated. This can be done by using URL tokens in the UrlAction element:

<UrlAction Url=”_layouts/mypage.aspx?listid={ListId}“/>

The {ListId} URL token will be automatically replaced with the ID of the list, in which the menu item is shown. In the mypage.aspx, you can retrieve the value of the listid parameter by making use of the QueryString. Once you’ve got the ID, the object model can be used to get a reference to the SPList instance of that list. According to the documentation on MSDN, the following URL tokens can be used:

  • ~site – Web site (SPWeb) relative link.
  • ~sitecollection – site collection (SPSite) relative link.
  • In addition, you can use the following tokens within a URL:
    • {ItemId} – Integer ID that represents the item within a list.
    • {ItemUrl} – URL of the item being acted upon. Only work for documents in libraries. [Not functional in Beta 2]
    • {ListId} – GUID that represents the list.
    • {SiteUrl} – URL of the Web site (SPWeb).
    • {RecurrenceId} – Recurrence index. This token is not supported for use in the context menus of list items.

    Unfortunately there is no token that will give you the URL of the page on which the feature’s link is being displayed. In many cases you want to have that URL to be able to redirect, after you’ve shown your custom functionality, to the originating page. SharePoint itself uses this technique a lot: in many URL’s you’ll find the Source parameter:

    http://wss.u2ucourse.com/Lists/Links/NewForm.aspx?Source=http%3A%2F%2Fwss%2Eu2ucourse%2Ecom%2Fdefault%2Easpx

    The URL above points to the NewForm.aspx for the a Links list. Normally when the user fill’s out this form and clicks OK, this page redirects to the default view of the list. Because this link has the Source parameter, when the user clicks OK (or cancel), the page will redirect to the default.aspx instead. You can add the Source parameter to a lot of pages in SharePoint, giving you full control over the redirecting.

    So the issue is: we want to include the URL of the originating page in the UrlAction element of the feature’s CustomAction, but all we get are a bunch of ID’s and some URL’s that are not useful for this scenario. As usual peeking in the machine room of SharePoint itself can give you some good ideas to solve this issue. The SharePoint guys themselves sometimes use Javascript functions in the UrlAction, instead of ordinary hyperlinks. Thus with some clever use of Javascript, it’s quite easy to solve the problem:

    <UrlAction Url=”javascript:window.location= ‘{SiteUrl}/_layouts/mypage.aspx?List={ListId}&amp;Source=’ + window.location”/>

    The actual link is a Javascript function that will navigate to a specific URL. This URL is a concatenation of the URL of the page to display (including for example the ID of the list as a parameter in the QueryString), and the Source parameter which is dynamically set the current page’s URL. Et voila, the constructed link will point to your page, and the redirect will always point to the page you started from.

    Extra: this tric can also be used to overcome a bug in SharePoint that causes a URL token of a CustomAction to be replaced only once. So if you have used the ListID token two times in a UrlAction element, only one of the token’s will be replaced with the actual ID of the list. The user “FlatEric” (what’s in a name?) explains this in the Community Content of the How to: Add Actions to the User Interface article on MSDN.

    I found an ugly way to bypass this flaw:
    <UrlAction Url=”javascript:function process(){var site='{SiteUrl}’;var item={ItemId};window.location.href=site+’/Lists/MyList/NewForm.aspx?ID=’+item+’&amp;Source=’+site+’/Lists/myOtherList/DispForm.aspx?ID=’+item;};process();”/>

  • Posted in MOSS 2007, WSS 3.0 | 19 Comments »

    Master Detail View – Data View Web Part

    Posted by Clayton James on May 21, 2008

    I have some time to kill as I sit in a Melbourne apartment waiting on a phone call to hopefully receive Internet access. So I thought I would write a blog entry (you know‚Ķ.turn a negative into a positive :)). But I will have to wait for reconnection before I can post this entry ūüėČ

    I was asked a question recently about creating a master-detail form for employees and their work resume history. I immediately thought of InfoPath but a requirement was it needed to be in the browser. Unfortunately the infopath master detail control doesn’t render in the browser so after some thought…out came the lovely Data View Web Part (DVWP). So this is how the story goes…

    1. Create a Resume Details list. Each row in this list must contain a column that links it back to the parent list. In my case Full Name.

    2. Create a blank web part page

    3. Open the site in SharePoint designer and open the blank web part page you just created and click in the top Header web part zone

    clip_image002

    4. Click the menu Insert –> SharePoint Controls –> Data View

    5. You will notice on the top right hand pane the Data Source Library is displayed. Select the Employees list and drag it into the Data View Web Part.

    clip_image004

    6. Edit the columns of the web part to include what you want. I have a column called Full Name that I want displayed.

    7. Now click in the Footer web part zone and Insert another Data View Web Part.

    8. Drag the Resume Details list in the Data View Web Part and edit the columns as shown

    clip_image006

    9. The next thing for us to do is create a connection between the two web parts so when I select an Employee their resume details are displayed. Right click the Employees DVWP and select Web Part Connections.

    10. You should see this dialog.
    clip_image008

    11. Click Next until you come the following dialog. Select the column that you want to make the connection between the two web parts.
    clip_image010

    12. Create a hyperlink on the connected field
    clip_image012

    13. Then click next and Finish the web part connection
    clip_image014

    14. Save the page in SPD and open the page in IE. You will now see the following screen. When you select an Employee the name is passed through to the Resume Details DVWP and filters the associated records

    clip_image016

    15. Now…what if you wanted to edit the details right here in the page…simple when using the DVWP. Go back to SPD and select the change layout option.

    clip_image018

    16. Select the following layout which is a Tabular Form Style. Don’t’ worry about the breaking of web part connections message. Everything should work fine.
    clip_image020

    17. Then select the Data View Properties and select the Editing tab and select all the check boxes and click OK.

    clip_image022

    18. Save the page and then view in the browser
    clip_image024

    19. Ok…so all is good. Now your optional exercise. Put in place some conditional formatting and maybe a Form Web Part passing in text values.

    clip_image026

    Posted in WSS 3.0 | 44 Comments »

    Not everything works using the SPSecurity.RunWithElevatedPrivileges

    Posted by Clayton James on May 15, 2008

    Web parts and application pages run under the context of the of the windows account.

    “When the code behind a Web Part or a custom application page executes in response to a user request, the code does not execute under the worker process identity of the hosting Web application. Instead, WSS uses impersonation to switch the Windows security context over to another Windows account. In fact, if you look inside the web.config file for a WSS Web application, you will see the following entry:”

    <configuration>
      <system.web>
        <identity impersonate="true" />
      </system.web>
    </configuration>
    
    http://msdn.microsoft.com/en-us/magazine/cc163287.aspx

    So if you are creating a web part that performs some type of operation…say updating user profiles using the UserProfileManager class, then you will receive permission errors because the windows account doesn’t have the required permissions. Even if you try to run the code using SPSecurity.RunWithElevatedPrivileges you will receive these permission errors.
    Note: It usually works in development because you are logged in as an administrator.

    So you have a couple of options:

    1. You will need to use the User Profile web service as there are some issues with the Object Model and elevation when using the  .
      http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3233224&SiteID=1
      http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3153689&SiteID=1
      http://msdn.microsoft.com/en-us/library/ms494053.aspx
    2. Complete ASP.Net 2.0 impersonation and use an account that has permissions
      http://msdn.microsoft.com/en-us/library/ms998351.aspx

    Posted in MOSS 2007 | 1 Comment »

    Developing ASP.Net 2.0 Code Behind pages for SharePoint: Using VSeWSS1.1

    Posted by Clayton James on April 13, 2008

    This is a guide that will take you through steps in creating a code behind file in Visual Studio for SharePoint development. Full credit to Andrew Connell on his blog entry which demonstrates this process by manually creating files for the deployment process.

    The difference with this article is that I wanted to complete the process using Microsoft’s Visual Studio Extensions WSS 1.1 (VSeWSS1.1) tool. Why, because I think this is the tool that should be used when doing any SharePoint development due to its integration with VS.Net, variety of templates, debugging integration, nice wsp viewer, auto generation of features and solutions, and it will continue to evolve over time.

    1/ First we need a Content page (.aspx) that will host our ASP.Net controls. Content pages need to conform to SharePoint master pages PlaceHolderContols. So a good place to create one is in SharePoint Designer.

    To create a Content page for SharePoint you can open SharePoint Designer and select File –> New –> Create from master page.This will create a blank content page as shown:
    clip_image002

    This page has no asp Content controls so you can go and add one.
    <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”></asp:Content>

    Inside the content control you can add html markup as shown below

    clip_image004

    3/ Copy the html (ctrl-A) from SharePoint Designer into notepad and save the physical file as CodeBehindDemo.aspx.

    4/ Open up Visual Studio and create a new Project and select the Empty SharePoint project and name it accordingly (Note: you need to install VSeWSS1.1 to get these templates).
    clip_image006

    5/ Once the Project is created right click the project and select Add New Item and select the Module template.
    clip_image008

    6/ Copy the CodeBehindDemo.aspx to the Module1 folder so it looks like the image below. Then create a new class file called CodeBehindDemo.cs. This will obviously be our code behind file.
    clip_image010

    7/ Write the following code in the CodeBehindDemo.aspx page. We need to explicitly declare the asp.net controls in the class file as the .aspx and .cs files are not compiled into a single (partial) class.
    clip_image012

    8/ Back in our .aspx page we need to reference our code behind class with the following page directive.
    <%@ Page Language=”C#” masterpagefile=”~masterurl/default.master” title=”|”

    inherits=”SharePointCodeBehindPages.CodeBehindDemo, SharePointCodeBehindPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5″ meta:webpartpageexpansion=”full” meta:progid=”SharePoint.WebPartPage.Document” %>

    Note: Check your public key token as yours will be different once you sign the assembly.

    9/ This is the code inside the Module.xml file.
    clip_image014
    <?xml version=”1.0″ encoding=”utf-8″?>
    <Elements Id=”581c7ebb-03bd-4d7d-ad4a-4e7ff446d2ac” xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <Module Name=”Module1″>
         <File Path=”CodeBehindDemo.aspx” Url=”CodeBehindDemo.aspx” Type=”Ghostable” />
    </Module>

    <CustomAction Id=”A6DED79F-05A5-4b1a-BD27-10B1A4AAC737″
         Location=”Microsoft.SharePoint.StandardMenu”
         GroupId=”SiteActions”
         Sequence=”99″
         Title=”Code Behind Demo”
         Description=”Code behind example”>
              <UrlAction Url=”~site/CodeBehindDemo.aspx” />
    </CustomAction>
    </Elements>

    10/ This is the code that is inside the Feature.xml file
    clip_image016

    <?xml version=”1.0″ encoding=”utf-8″?>
    <Feature Id=”39fd665e-e168-42fe-ab11-ebea99e0a378″ Title=”Module1″ Scope=”Web” Version=”1.0.0.0″ Hidden=”FALSE” DefaultResourceFile=”core” xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <ElementManifests>
         <ElementManifest Location=”Module1\Module.xml” />
         <ElementFile Location=”Module1\CodeBehindDemo.aspx” />
    </ElementManifests>
    </Feature>

    11/This is the code inside the manifest file
    clip_image018

    <?xml version=”1.0″ encoding=”utf-8″?>
    <Solution SolutionId=”e8fa762e-9f02-4646-9fde-cf17ed7288d6″ xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <FeatureManifests>
    <FeatureManifest Location=”Module1\feature.xml” />
    </FeatureManifests>
    <Assemblies>
    <Assembly DeploymentTarget=”WebApplication” Location=”SharePointCodeBehindPages.dll”>
    <SafeControls>

    <SafeControl Namespace=”SharePointCodeBehindPages” Safe=”True” Assembly=”SharePointCodeBehindPages” TypeName=”*” />
    </SafeControls>
    </Assembly>
    </Assemblies>
    </Solution>

    12/ Before we create and deploy the solution first build the project, make sure you don’t receive any errors and then check the new WSP View in Visual Studio to make everything is fine. You made need to click the Refresh button to display the wsp structure. One of the nice features about the extensions is that it is integrated with Visual Studio so if one of the .xml files has an error then it is displayed in the Error List pane and nothing is displayed in the WSP View, it is just blank. Remember to click the refresh button.
    clip_image020

    13/ Now all that is needed is to deploy the Solution (.wsp) to the farm. Very simple, right click the project and select Deploy.
    clip_image022

    14/ Make sure everything is successfully built and deployed
    clip_image024

    15/ Once built successfully you can view the .wsp file which is located in the projects bin/debug folder
    16/ Ok, now lets go and test the page in SharePoint. We have a nice Custom Action we can click that will take us to the page.

    clip_image026

    Enter you name and click the button.

    clip_image028

    16/ So there you have it. A code behind page built in Visual Studio all wrapped up in a nice solution (.wsp) for deployment across the farm using the new Visual Studio Extensions for WSS 1.1 tool.

    Posted in WSS 3.0 | 57 Comments »

    Registering SharePoint Event Handlers

    Posted by Clayton James on April 2, 2008

    The first thing you want to do if you are writing event handlers for SharePoint is download the VSeWSS 1.1. This has a whole bag of goodies for us SharePoint developers  including a nice template for creating event handlers. Unfortunately it is only available in VS2005.

    There are basically two ways you can register an event handler to a SharePoint list or content type.

    1. Features – declarative approach
    2. Features and OM combined

    Ok, so when would you use one instead of the other.

    1. Features
      Basically you can use the Features declarative model when you want to register an event handler to all lists of the same type (ListTemplateId). If the ListTemplateId = 101 (Document Library) as shown below then when the Feature is installed and activated then the event handler will associated to all document libraries in the site.
      Everything is declared in the ElementsManifest.xml file.
      <Elements>
      ¬† <Receivers ListTemplateId=”101″>
          <Receiver>
            <Name>SimpleEvent</Name>
            <Type>ItemAdded</Type>
            <SequenceNumber>10000</SequenceNumber>
            <Assembly>SimpleEventHandler, Version=1.0.0.0, Culture=neutral,
              PublicKeyToken=10b23036c9b36d6d</Assembly>
            <Class>CJ.Samples.SimpleEventHandler</Class>
            <Data></Data>
            <Filter></Filter>
          </Receiver>
        </Receivers>
      </Elements>Notes:
      ListTemplateId: This specifies which list to associate the event handler. 101 = document library. This is an all or nothing approach which means I can not associate the event handler to only one document library.
      ItemAdded: This is the event that will be raised when this action takes place.
      //Override the ItemAdded event and add your own code
           public override void ItemAdded(SPItemEventProperties properties)
           {
               SetSecurityForNewItem(properties.ListItem.File, properties.ListItem.ParentList);
           }
      Assembly, PublicKey Token, Class: Self explanatory. The event handler must be installed in the GAC before is can be associated to a list.
      SequenceNumber: This allows you to have multiple event handlers registered and specifiy their order of execution.
      Data
      Filter
    2. Features and Object Model
      In this approach we have the ability to register our event handler to only one (or more) list/content type. Our solution (.wsp) would manage the process of installing our event handler assembly into the GAC and activate the Feature. When the Feature is activated we can run a Feature Receiver to attach our event handler to a specified list as shown below.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWeb web = properties.Feature.Parent as SPWeb;
    ¬†¬†¬† web.Lists[“Appointments”].EventReceivers.Add(
          SPEventReceiverType.ItemAdded,
    ¬†¬†¬†¬†¬† “CJ.SharePoint.Eventhandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3a29000ff02kt1bn”,
    ¬†¬†¬†¬†¬† “CJ.SharePoint.Eventhandlers.ItemPermissionsEventHandler”);
    }

    Side note on Event Handlers
    If the event handler modifies the current list or current list item then you must call the this.DisableEventFiring() method before committing the change, and then before you leave your event handler code call this.EnableEventFiring() method to turn events back on. This stops recursive event firing from occurring where the list item is being modifed by the event handler which in turn raises the event handler again, thus causing an infinite loop.

    Posted in WSS 3.0 | 8 Comments »

    Custom web.config settings in SharePoint

    Posted by Clayton James on March 19, 2008

    I have come across two ways to modify the web.config with custom nodes when using SharePoint. Yes, I know SharePoint solutions (.wsp) allow you to update web.config for safe control entries and other areas but this model doesn’t allow for any modification you want…lets say a WCF service <system.serviceModel>.

    Option 1
    You can use the SPWebConfigModification class that is inside the Microsoft.SharePoint.Administration.dll. Its purpose is to write nodes and attributes into the web.config file. This is a great approach when you want to deploy your custom settings via a features/solutions deployment.

    SPWebService service = SPWebService.ContentService; SPWebConfigModification myModification = new SPWebConfigModification(); myModification.Path = “configuration/SharePoint/SafeControls”; myModification.Name = “SafeControl[@Assembly=’MyCustomAssembly’][@Namespace=’MyCustomNamespace’][@TypeName=’*’][@Safe=’True’]”; myModification.Sequence = 0; myModification.Owner = “User Name“; myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; myModification.Value = “<SafeControl Assembly=’MyCustomAssembly’ Namespace=’MyCustomNamespace’ TypeName=’*’ Safe=’True’ />”; service.WebConfigModifications.Add(myModification); /*Call Update and ApplyWebConfigModifications to save changes*/ service.Update(); service.ApplyWebConfigModifications();

     http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx

    So the above code would go in a FeatureReceiver event when activated and removed when deactivated.

    Option 2
    If you want to write custom nodes into a web.config when the web application is first created you could also do the following.

    When a Web Application is first created WSS copies the web.config file from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG to the root folder of the Web Application. But before this file is copied it checks the CONFIG directory for any xml file that has a name in the format webconfig.*.xml and merges the contents with the web.config.

    So you would create a file called webconfig.myname.xml and save it to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG

    However, this approach will not modify existing web applications.

    webconfig.myname.xml contents:
    <?xml version=”1.0″ encoding=”utf-8″ ?>
    <actions>
    <add path=”configuration/appSettings”>
    <add key=”MyFilePath” value=”C:\temp\path\” />
    </add>
    <add path=”configuration”>
    <connectionStrings />
    </add>
    <add path=”configuration/connectionStrings”>
    <remove name=”MySqlServerConnection” />
    <add name=”MySqlServerConnection” connectionString=”server=[server];database=
    db];Integrated Security=SSIP;” providerName=”System.Data.SqlClient” />
    </add>
    </actions>

    So this needs to be completed on each web front end server. So to eliminate the manual approach again you can and package this up into a solution so WSS manages the deployment across the farm.
    Add the file to a solution. A file to be deployed to the CONFIG folder can be inserted by using the <RootFile> element:

    manifest.xml example:
    <Solution xmlns=”http://schemas.microsoft.com/sharepoint/&#8221; SolutionId=”GUIDHERE”>
    <RootFiles>
    ¬†¬† <RootFile Location=”CONFIG\webconfig.myname.xml”/>
    </RootFiles>
    <!– rest of solution manifest here
    <FeatureManifests>… and other elements
    –>
    </Solution>

    http://msdn2.microsoft.com/en-gb/library/ms439965.aspx

    Posted in WSS 3.0 | 21 Comments »

    System Content Type IDs

    Posted by Clayton James on March 13, 2008

    Content Type ID-numbers Рreference list

    Name Content Type ID Description
    Item 0x01 Create a new list item.
    Reusable HTML 0x01002CF74A4DAE39480396EEA7A4BA2BE5FB Reusable HTML
    Reusable Text 0x01004D5A79BAFA4A4576B79C56FF3D0D662D
    Page Output Cache 0x010087D89D279834C94E98E5E1B4A913C67E Page Output Cache is a system content type template created by the Publishing Resources feature to define cache profiles.
    Document 0x0101 Create a new document.
    System Page Layout 0x01010007FF3E057FA8AB4AA42FCB67B453FFC1 System Page Layout is a system content type template created by the Publishing Resources feature, and it cannot be modified. To add columns to page layouts in the page layouts gallery and master page gallery, update the Page Layout content type template.
    Page Layout 0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811 Page Layout is a system content type template created by the Publishing Resources feature. All page layouts will have the column templates from Page Layout added.
    System Master Page 0x0101000F1C8B9E0EB4BE489F09807B2C53288F System Master Page is a system content type template created by the Publishing Resources feature, and it cannot be modified. To add columns to master pages in the page layouts gallery and master page gallery, update the Master Page content type template.
    Publishing Master Page 0x0101000F1C8B9E0EB4BE489F09807B2C53288F0054AD6EF48B9F7B45A142F8173F171BD1 Master Page is a system content type template created by the Publishing Resources feature. All master pages will have the column templates from Master Page added.
    Office Data Connection File 0x010100629D00608F814DD6AC8A86903AEE72AA
    Universal Data Connection File 0x010100B4CBD48E029A4AD8B62CB0E41868F2B0 Provide a standard place for applications, such as Microsoft Office InfoPath, to store data connection information.
    System Page 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2 System Page is a system content type template created by the Publishing Resources feature, and it cannot be modified. To add columns to the Pages library, update the Page content type template.
    Page 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39 Page is a system content type template created by the Publishing Resources feature. The column templates from Page will be added to all Pages libraries created by the Publishing feature.
    Article Page 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D Article Page is a system content type template created by the Publishing Resources feature. It is the associated content type template for the default page layouts used to create article pages in sites that have the Publishing feature enabled.
    Welcome Page 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4 Welcome Page is a system content type template created by the Publishing Resources feature. It is the associated content type template for the default page layout used to create welcome pages in sites that have the Publishing feature enabled.
    Redirect Page 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900FD0E870BA06948879DBD5F9813CD8799 Redirect Page is a system content type template created by the Publishing Resources feature. It is the associated content type template for the redirect page layout
    Form 0x010101 Fill out this form.
    Picture 0x010102 Upload an image or a photograph.
    Unknown Document Type 0x010104 Allows users to upload documents of any content type to a library. Unknown documents will be treated as their original content type in client applications.
    Master Page 0x010105 Create a new master page.
    User Workflow Document 0x010107 Items for use in user defined workflows.
    Wiki Page 0x010108 Create a new wiki page.
    Basic Page 0x010109 Create a new basic page.
    Web Part Page 0x01010901 Create a new Web Part page.
    Link to a Document 0x01010A Create a link to a document in a different location.
    Dublin Core Columns 0x01010B The Dublin Core metadata element set.
    Event 0x0102 Create a new meeting, deadline or other event.
    Issue 0x0103 Track an issue or problem.
    Announcement 0x0104 Create a new news item, status or other short piece of information.
    Link 0x0105 Create a new link to a Web page or other resource.
    Contact 0x0106 Store information about a business or personal contact.
    Message 0x0107 Create a new message.
    Task 0x0108 Track a work item that you or your team needs to complete.
    Workflow Task 0x010801 A work item created by a workflow that you or your team needs to complete.
    Office SharePoint Server Workflow Task 0x01080100C9C9515DE4E24001905074F980F93160 A work item created by a workflow that you or your team needs to complete.
    Administrative Task 0x010802 An administrative work item that an administrator needs to complete.
    Workflow History 0x0109 The history of a workflow.
    Person 0x010A
    SharePointGroup 0x010B
    DomainGroup 0x010C
    Post 0x0110 Create a new blog post.
    Comment 0x0111 Create a new blog comment.
    Far East Contact 0x0116 Store information about a business or personal contact.
    Folder 0x0120 Create a new folder.
    RootOfList 0x012001
    Discussion 0x012002 Create a new discussion topic.

    Posted in MOSS 2007, Office 12 | 3 Comments »