Sharepoint – WSS 3 / Moss

Having recently attended a developer course in Wss3 development I intend to update many of the old 2003 web parts and techniques I had previously developed.  However I have a backlog of stuff to clear at work and no environment to build them on as yet.  When I get time and VPC sorted I will get round to it.

So anyone interested in sharepoint might want to subscribe to the sharepoint category of this blog (or not), rather than read the trite and silverlight and sap and other stuff.

Sharepoint / Silverlight Parts RC1 Update

As the RC1 has been released I had five minutes spare to ensure they worked in RC1. 

Here are the links

PhotoViewer. : The stand alone version of the WebPart project I do the testing and enhancements on first, its easier to see when I have messed it up here.

**Update** Moved to codeplex.

Currently in a laughable state of development, try it you will see.

Silverlight Photo Viewer WebPart : The Sharepoint Portal version of Photo Viewer.  Coded as an Installable WebPart.  This means that if installed on a portal level then any user on any portal are can jsut drop this on and it displays from the default Image Library list.  This needs some work to make it work “MySite” cos it explodes at the moment, also I need to try it on Sub Sites of MySite and WSS Sites.  This should work on Sharepoint 2003 and MOSS 2007 as all 2003 webparts should (mostly).

Silverlight WebPart Template : A Really Simple Webpart project that implements a button that says click me.  It has mouseover anims and fullscreen and thats it.  What’s special about this is that the webpart is coded to allow multiple instances of this part on the same page.  The photo viewer code is based on this.    This should work on Sharepoint 2003 and MOSS 2007 as all 2003 webparts should (mostly).

Would really like to hear if you implement this and what you think and what improvements could be made.  I know of a few but I’m interested in your opinions and there should be a lot considering how many downloads there have been lately.

Technorati tags: , ,

Updated WebPart

I had chance to make the xaml nicer last night so I updated the original article and the source code.  I also included a CAB file for those who can’t build the source code.  Again see original for source and cab links.

Technorati tags: , ,

Sharepoint Silverlight Image Library Viewer Part

Well that’s a long title but I think you get the idea of what this post is about.

Building on top of my web part template I thought I ought to do something useful that I could share. So Combining the ability to peruse lists from a webpart and mangling this into Silverlight I made a webpart Image Library viewer.

Now this is pretty rough and ready the xaml is from the VB school of design, “Grey Blue and Boxy”, but get a designer on the case and your away.  It contains elements of a jscript Control.  The photos at the bottom scroll left and right and are added dynamically.  This is a good use of the CreateFromXaml but using the “true” option for the namespace scope, which is better than find and replace of the video library example.  It does full screen by clicking the little grey blue square (see what I mean about design) which is taken from the video library sample and doesn’t scale to exactly 4:3, again I don’t have time to investigate, it involves pencils and math’s and I’m a bit busy.

The webpart itself looks specifically for a list called “Image Library” one of the default lists created by portal sites.  This can be changed so that you could have a toolpart selection.  It relies on the list being an Image Library list.  If the list is not there it blows up I haven’t spent long on this making it bomb proof.

If there are no pictures in the image library it resorts to displaying text in the webpart that the list is empty, not some custom display in the Silverlight part.

Read the rest of this entry »

SPSite.LastContentModifiedDate

This can’t be right, it’s insane.  What’s insane ? Well it appears that the LastContentModifiedDate gets updated when the Site Usage is re-calculated.  So my Last Modified webpart is made pretty much useless by having the SiteUsage data enabled.

That blows. Hope its just coincidence.

 

Technorati tags: , ,

That Todd Bleeker

menupart.jpg 

Whilst poking about on sharepoint sites I was looking at Todd’s site again, and stumbled across another of his CEWP again, this one was for a menu part, its great , as they always are leveraging the power of sharepoints built-in functionality but what I never knew before was just how easy it was to generate sharepoint menus.

This is the html for two menu items and its opening link

<menu id=”myLinks” class=”ms-SrvMenuUI”>

<ie:menuitem

iiconSrc=”http://www.highdots.com/website-ranking-checker/images/search_engines/google.gif”

onMenuClick=”window.location.href=’http://google.com’;”

>Google</ie:menuitem>

<ie:menuitem

iiconSrc=”http://www.highdots.com/website-ranking-checker/images/search_engines/msn.gif”

onMenuClick=”window.location.href=’http://msn.com’;”

>MSN</ie:menuitem>

</menu>

<div class=”ms-HoverCellInActive”

onmouseover=”this.className=’ms-HoverCellActive’”

onmouseout=”this.className=’ms-HoverCellInActive’”>

<a id=”menuLink”

style=”CURSOR: hand”

onclick=”JavaScript: if(!myLinks.isOpen())

myLinks.show(this, true, 0, 0, 0);”

tabindex=”0″>

Search Engines

</a>

</div>

 Taken from http://mindsharpblogs.com/todd/archive/2006/08/15/1242.aspx

Now because I spend my time writing dynamic webparts (ie not fixed content) I can name the menu based on the webparts clientId and have these littered all over a page.

Must think up some use for it now.

Technorati tags: , ,

Ajax and Sharepoint 2

Subtitle:Don’t you think the way lists display suck ?

Well I do, no in the web parts themselves, but in the inevitable postback to a crappy looking list item page.

In the previous post you could see the web part I was working on, well its just a demo piece and needs a lot of work, but I figure why should I do all that work I’ll let you do some.  Actually I may not have time to finish this one so I thought I’d put out what I had done.

The web part allows you to select a list that is currently available on this current site. You have to enter the Main field name in the Text box below and its away.  This part will rip through the list contents and spit them out with a link in the web part.  When you click that link the Ajax stuff fetches the list data item and displays it in the box, fast.

Now there is a lot to do here, things like provide html editing for the list display both list and popup designs.  Use the ID instead of the “Title” field (duplicates won’t work in this version)

Also figure out the field type and display appropriately being the main one.

Lots left to do but you can do it.

When you create this you MUST GAC IT.  It was developed with Sharepoint security at FULL, figure it out for yourself if you want a better config.

The web.config needs the HTTP Handler adding (you own key remember)

<httpHandlers>
<add verb=”GET” path=”DynamicCustomListPart.ashx” type=”DynamicCustomListPart.DynamicCustomListWebPart, DynamicCustomListPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=*************” />
</httpHandlers>

Source Code

*NB.  This is a demo and not production software, use at own risk.

 

Technorati tags: , , ,

Sharepoint and Custom HttpHandlers

If you are daft enough to remove your HttpHandler from the GAC don’t be surprised if sharepoint goes bang.

I did just that and hit Site Settings and got a plain file not found message, not very helpful.

I narrowed it down to the last scarey thing I did which was HttpHandlers, deleted the entries and all was working I then figured I removed it from the GAC and sps bin folder so Sharepoint was not finding the dll.  Pretty poor message though.

WebParts and Ajax

I have been playing about with ajax recently,  actually I’ve been doing ajax and dynamic web applications since IE4 was released, I was lucky enough to spend 9 months programming a client side dynamic application back then using RDS MTS and dhtml classes, its just this .NET postback model dragged me away from it.  But anyway I’ve been playnig with it again.

What I wanted to do was use ajax in a webpart however its the same old story, having to have a seperate web site to host the data side of the relationship then configure sharepoint to allow that site as an exclusion url…….

Well no need I can do it with HttpHandlers in the same web part that is making the request, this should overcome the security issue of cross website posting, instead of having to resort to Dynanic Script calling using JSON (see links below)

http://tagneto.org/how/reference/js/DynamicScriptRequest.html

http://ajaxpatterns.org/On-Demand_Javascript

Now I haven’t tried it yet, bit busy at the minute, but I have no reason to believe it won’t work, after all the images thing did and this is very similar.

*Update* : It worked just fine, however I used Json output instead of trying to parse XML the end product seemed faster.  Also I still used the dynamic calling method, so this is not a full test of security bypassing but it keeps all code together, except for the remote data web service, as the json object is a web service proxy also.
Again you need to check that sharepoint is not being overloaded by your webpart being a httphandler

*Update Again* : I have more posts on this site and some working source code.  See
Ajax and Sharepoint
Ajax and Sharepoint 2
Yet another Ajax Sharepoint Part

tags: , , ,

Dynamic Images from Web Parts

What are you mad !! You can’t do it, how on earth are you going to suddenly be called again as an image and write binary data out.  

If you’ve read previous posts you will see that I have been writing a web part that gets SiteUsageData and displays it.  It uses some nasty COM+.  I got to thinking how on earth am I going to graph this dynamic data that changes per site?

HttpHandlers - for a bit more info on HttpHandlers see here on Scott Hanselman’s blog.

Now your up to speed on them, how can we use them with a part. 

First we have to spit out the IMG tag in your render section.

textWriter(”<img src=’_layouts/MyWebPartImage.ashx/’>”);

Of course that on its own does nothing, but note the url “_layouts”, not “/_layouts” this is very important as your part will run in the Site context of “/” if you do, instead of the current site.

Second you need to register this HttpHandler in web.config

<add verb=”GET” path=”MyWebPartImage.ashx” type=”Binaryjam.MyWebPartNs.MyWebPart, Binaryjam.MyWebPartNs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5**************d” />

Replace those details with your own namespace, typename, public key.  Ahh Did I say you need to GAC this part.  I haven’t experimented with not GACing this feel free to but to be sure GAC IT.

Third add the IHttpHAndler interface to your web part class

public class MyWebPart: WebPart, IHttpHandler

Nearly there now add your Interface methods, remember Scott’s article ? Here is a simple example of this:

public void ProcessRequest(HttpContext context)
{
    HttpResponse response=context.Response;
    HttpRequest request=context.Request;
    response.ContentType=”image/jpeg”

    Graphics g=null;
    System.Drawing.Image image=null;
    image=new Bitmap(Width,Height,PixelFormat.Format32bppArgb);
    g=Graphics.FromImage(image);
    g.FillRectangle(new SolidBrush
            (Color.White),0,0,image.Width,image.Height);
    g.DrawString(”YooHoo”,new Font(”Verdana”, 10.0f),
             new SolidBrush(Color.Black),0,0);
    image.Save(response.OutputStream,ImageFormat.Jpeg);

}

public bool IsReusable
{
  get
  {
    return true;
  }
}

These pieces of code give you the basics to dynamically generate an image from a web part.  Now because the webpart is being created again in the context of the site its running in in theory its Properties are populated, however you would need to check this.  For my use I only needed to now the site Context, I could then use the Sharepoint API and the site context

SPWeb thisWeb = SPControl.GetContextWeb(Context);

To get the data I need.  You could use the API to access list information in a site and graph that too.

And no I don’t have a full code example, my graphics code is too embarrassing.
:-)

 

Its here I might point out that doing this might be a really bad idea, lets face it we don’t know what’s happening behind the scenes, but lets have a guess.  You have already hit this page once to display the web part. To display the image the site is visited a second time, admittedly not the rendered page but the site all the same.  Now what could be happening here is that the Sharepoint httphandlers, because remember its not the aspx ones running, initialise loads of Sharepoint stuff.  Then you create a webpart, now either the Sharepoint context exists already of the webpart creates it, considering that on a page could be multiple web parts are they all creating contexts ? or calling a static to get it ?  Anything could be happening here.   On the other hand is it as bad as hosting an image held in a site list in a CWP part on your site ?  Probably very similar.

If there are any Sharepoint under-the-covers experts who know what’s happening, let me know please.

tags: sharepoint+webparts, sharepoint, GetUsageData, evil+voodoo+in+sharepoint