Navigation menus are one of the central points of any site. Since SharePoint is now more than ever being used to drive public sites – popular navigation techniques including Flash menus are now a topic for discussion when integrating components to SharePoint driven site. End result: users would see nice Flash menus instead of a standard links and tabs generated by SharePoint.
Needless to say that those menus have to be driven by the content within SharePoint and items have to be dynamic just like out-of-the-box. In my scenario, client already had several types of menus that are essentially Flash objects and can be easily placed on any webpage including SharePoint master page using an <object> tag. Once our Flash is placed on the page and executed – we need to access SharePoint to extract actual object representing SharePoint menu items. In our example here we will list all of the sub-sites under our top level site and consume them within our Flash object.
So let’s see what we’re looking at here. Since Flash is not capable of accessing SharePoint object model directly – one of the ways we can extract the names and URLs of our sub-sites is to use SharePoint web-services. Depending on the type of the data we need to extract from SharePoint – there are different web-services we will be working with. In this case we’re looking at
http://<server-url>/_vti_bin/webs.asmx
to extract sub-sites.
If you tried accessing SharePoint web services from other than .NET environment, such as a static web page – you probably already know that de-serializing your data and extracting pieces you need will require quite a bit of manual work. The benefit here is that you have access to many of the properties available in the object.
In our scenario – we just need a URL of the sub-site and its title. Once we have that information, we can create menu items in our Flash and display them. To extract just those two properties, URL and sub-site title, we could use an alternative solution below.
The alternative is to create a SharePoint custom layout page (resides under http://<server-url>/_layouts) that will return simple delimited or XML structured data such as title of the site and URL. This option is only available if you are allowed to deploy custom layout pages to the environment. Considering the fact that you will be modifying the master page of the site – this shouldn`t be a problem.
So let`s take a look at what the custom layout page which extracts our sub-sites is going to look like:
|
<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master” Inherits=”Microsoft.SharePoint.WebControls.LayoutsPageBase” EnableViewState=”true” EnableViewStateMac=”false” %> <%@ Import Namespace=”Microsoft.SharePoint” %> <%@ Register TagPrefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register TagPrefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <script runat=”server”> protected override void OnLoad(EventArgs e) Response.WriteLine(“<subsite name=’{0}’>{1}</subsite> “, oWebsite.Url, oWebsite.Title); } </script> <asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”></asp:Content> <asp:Content ID=”PageTitle” ContentPlaceHolderID=”PlaceHolderPageTitle” runat=”server”></asp:Content> <asp:Content ID=”PageTitleInTitleArea” ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea” runat=”server”></asp:Content> |
Pretty straight forward stuff here, we’re accessing all of the sub-site under the current site collection and displaying their URL and title creating an XML structure. If we executed this layouts page by hitting it from http:///_layouts/ .aspx we would get out URLs and titles as a simple webpage.
We are not required to create XML structure to consume it in Flash, in fact we can delimit out objects however we like as long as we can easily de-serialize them later.
Now that required information is available in a simple format, all we need to do is to request this page from our Flash clip and render menu objects with respective URLs and site titles.
Let’s take a look at such sample Flash code (ActionScript):
| var myXML:XML = new XML(); myXML.ignoreWhite=true; myXML.load(“http://<server>/_layouts/<page_name>.aspx“); myXML.onLoad = function(success) { if (success) { var myWeb = myXML.firstChild.childNodes; for (i=0; i< myWeb.length; i++) { var webNumber = i+1; var webName = myWeb[i].attributes.title; var webURL = myWeb[i].firstChild.nodeValue; trace (“My web number “+webNumber+” is titled “+webName+” and its URL is “+webURL+”.”) } } }; |
That is the core of it, now you can tweak your ActionScript to feed data into the presentation of your menu items.
If you’re into experimenting, you can probably see variety of application here already which don’t have involve menus; you can build various Flash components that grab their dynamic content from your site and not only.
Here are some good references for starters:
http://www.republicofcode.com/tutorials/flash/xml/
http://msdn.microsoft.com/en-us/library/ms543497.aspx
Good Luck!
Yaroslav,
This is a wonderful article, thank you. I am in the process of creating a SharePoint MOSS site for a customer and integrating Flex controls and interactive elements. Your solution will come in most handy.
I am wondering though, is it possible to also write back to SharePoint using this webservice or a similar one? I have been struggling trying to create a Flex interface that will allow users to enter data and have it stored into lists and libraries. Two examples would be to register to be a member of a community and you enter your name in the name picker and press the “submit” button. This then adds your name to a SharePoint list. The second would be to use Flex to upload a document such as a Word file and have it stored in a library. Flex uses MXML and ActionScript and compiles as a .swf object. I am really looking forward to your comments and suggestions. I will re-post my results so you can see the fruits of our labor. I am new to writing C# and web services although I know my way around SharePoint as an interface and UI developer. Any assistance or suggestions you could offer to help me write the solution and the steps to integrate it would be most helpful.
Thank you
Alex Dove
Hi Alex,
Yes, it is possible to write back to sharepoint from a flash application. The same way you`d read the data using a webservice. If you have complex functionality when writing back to sharepoint – the easiest is to create a custom web service that will live in sharepoint layouts or isapi folder and accept your input data from flash by using URL parameters. On a back end of your webservice you could make local calls to the sharepoint object model which is way easier than using some of the standard sharepoint web services.
This article will be a good starting point, also check out the references at the bottom to some of the useful resources
I have been working on a solution which appears like it would work fine. The source code and examples are found on Code Project http://www.codeproject.com/KB/aspnet/FlexASPWebService.aspx?msg=3270246#xx3270246xx This Flex/ASP example uses a web service to communicate to a SQL database. Flex makes a web service call to the .asmx file via WSDL and the magic happens. I am running into a roadblock as I receive an error that the app cannot find the WSDL. I have tried to run the same WSDL URL in a browser and I get an server application error.
I also tried a solution found at http://shardulbartwal.wordpress.com/2008/03/20/import-web-servicewsdl-wizard-in-flex-30/ to load the WSDL file directly into Flex, but I ran into another roadblock. When I get to this step below Flex gives an error that it cannot find the WSDL file either…
Here is the WebService call from Flex…
The files from Code Project contain a directory structure as such:
TestWebService\Service.asmx
TestWebService\Web.config
TestWebService\App_Code
TestWebService\App_Code\Service.cs
TestWebService\App_Data
The Service.cs file is inside the App_Code directory and is referenced from the Service.asmx file with this code:
My Flex file calls the Service.asmx?WSDL which then calls the file Service.cs and then it breaks.
The Flex app error states it cannot locate the WSDL. Any ideas?
I don’t know what I am doing wrong…