More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  Michael's Coding DenProfileFriendsBlogMore Tools Explore the Spaces community

Michael's Coding Den

Applied Web: SharePoint, ASP.NET and AJAX
September 28

SharePoint Mirroring

There are number of posts and documents about how to setup mirroring of SharePoint content DB, but when I started my mirroring I stumbled over number issues, which I probably missed in documentation and which took some of my time to find out what was wrong. So in this post I’d like summarize all important parts of setting SharePoint mirroring.

Refer to detailed description in the end of this post to get the initial understanding.

  1. Prepare all you SharePoint Content databases for recovery. Use “ALTER Database <databasename> SET RECOVERY FULL;“ SQL command against all databases which will participate in backup and mirroring.
  2. (Optionally) Prepare content databases to be detached from web application, because in future you could rename it. To do this run “stsadm -o preparetomove -contentdb SQLSERVER:DBNAME –site <url>”.
  3. Make the SharePoint farm backup, and restore it on your Disaster Recovery (DR) box. Use OOTB backup/restore – Central Admin –> Operations –> Backup. The reason to restore SharePoint on DR box instead of straight mirroring is to have everything set and configured absolutely the same as on production box, to have minimum restoration time.
  4. After you restore your instance on DR box close SharePoint Central Admin. You don’t need it anymore :)
  5. Make SQL backup of your SharePoint DBs and their LOGs from production box, which will be mirrored. Usually only content databases are mirrored - search and other stuff can be missed, because it’s not so vital as content DB. I had number issues with making SQL backups and restore DBs on DR box, after you restored your new instance, so, I found more convenient to provide new copy of all DBs specially for mirroring. Make this backup with SQL commands “BACKUP DATABASE/LOG” and copy those files to DR box.
  6. Go to SQL Management Studio and delete all SharePoint DB which you want to mirror.
  7. Restore your databases with “NORECOVERY” attribute. UI doesn’t help you, so we are using SQL command “RESTORE DATABASE … NORECOVERY …” for this.
  8. After restoration completed you will see your DB with new icon and having “(recovering…)” status. Now time to apply the logs with the same “NORECOVERY” attribute and the similar command “RESTORE LOG … NORECOVERY…
  9. Wait a couple of minutes, allowing SQL server to restore some stuff.
  10. Now connect to Production SQL instance from DR box, select the database you just restored in DR, and right-mouse clicking, selecting tools->mirroring. Mirroring Wizards will start. Go through all steps. Ignore mirroring endpoints name difference. But pay attention on “encryption” settings on principal and on mirror boxes – they must be the same. Use next command to change these settings “ALTER ENDPOINT Mirroring FOR DATA_MIRRORING (ROLE = PARTNER, ENCRYPTION = SUPPORTED)” to be the same among principal and mirror boxes.
  11. Activate mirroring in the end of Mirroring Wizard, and you DB status will changed to “principal”/”mirroring”.
  12. You might have security error, saying that your DR box can’t connect to partner (production box). Go to SQL again and run the following “alter database myDatabase set partner = 'TCP://abc.domain.net:7024';
  13. Repeat everything from step 6 to 11 for all SharePoint databases.
  14. To switch to DR box and start using mirrored databases, you need to go to mirroring window again and press “FAILOVER” button. This will switch your databases and DR boxes will be active. Without failover you site on DR box won’t be accessible.

 

Troubleshooting:

1) User SQL Management Studio, right mouse click on DB, Tasks->Launch Database Mirroring Monitor to check the status of your mirroring databases.

2) You can have the following error “Cannot open database "<…>" requested by the login. The login failed. Login failed for user '….'.” when you try to use “stsadm –o addcontentdb …”. This happens when you DB not in failover status. You need to make your DR failovered (active) and only then add content DB

 

That’s all. I hope this post will save some of your time when you start your SharePoint mirroring.

 

More reading:

 

Mirror: SharePoint Mirroring

Starting SharePoint solution and planning your documentation

When a new SharePoint project is about to start I use the following steps to design and plan solution

  1. Creating Vision/Scope
  2. Site structure and Navigation
  3. Use Case Scenarios
  4. Data Flow scenario
  5. Content location
  6. Site Collection Boundaries
  7. List of required features and site definitions
  8. Security: Roles and Permissions
  9. Page Wireframes: layouts and content types
  10. Targeting
  11. Search strategy (scopes, authoritative, best bets)
  12. Infrastructure Plan 
  13. Disaster Recovery
  14. Deployment plan

    Take into account that SharePoint SDLC differs from standard development, and not all projects require those steps.

    Mirror: Starting SharePoint solution and planning your documentation

    September 27

    MS officially supports SharePoint virtualized environment

    Today @jthake posted info about the recent announcement from Microsoft that they finally started to support “Virtualized SharePoint environment” for

    • Virtual PC
    • vmWare
    • Win2k8 hyper-v

    What does it mean for end-users, developers or IT guys?! Nothing.

    It mostly the question of taking the official decision for managers, what and where will be deployed. Because in case of any problems Microsoft will help you in troubleshooting, but not for SharePoint under one of virtualized environment. You must had a installation on physical boxes.

    Now it’s now an issue. They announced support of virtualized SharePoint environments

     

    Mirror: MS officially supports SharePoint virtualized environment

    September 19

    SharePoint 2007 migration tips

    Working of migration of SPS to MOSS 2007 in these days and would like to share my experience about number of small tricks, which really annoys you if you don’t know them, and which could save hours during your next migration

    1. Remove EXE, MSI, DLL extension from blocked types, because these files could exist in your collection and your can’t export such sites. (I usually remove everything from there)
    2. Check source web.config to migrate all 3rd party Web Parts into new environment (use –haltonwarning in stsadm –o export to find the pages with missed Web Parts and then navigate to source pages to export DWP from there)
    3. Export with –incluseuseonwers attribute to
    4. Change the maximum upload file size: Central admin ->Application management ->Web Application General Settings. Set 250mb for example, or the size of the biggest file
    5. Set yourself as secondary admin(stsadm –o siteowner –url <site> –secondarylogin <user_name>), because export wont work against content if you are not admin on target site collections
    6. Before making export make sure that you are site owner for the sites you are going to export (stsadm –o siteowner –url <site> –secondarylogin <current_account>). Otherwise you can’t create any sub-sites during importing and will get strange errors.
    7. Use STSADM –o export with cabsize 1024, otherwise you silently miss some files in your export package if your site size more that 25Mb (default value)

     

    Update: be very careful with renaming database, because if you will do it wrong way you DB is completely screwed, and there is no way to return it back. Refer to this document http://blogs.technet.com/corybu/archive/2007/06/01/detaching-databases-in-moss-2007-environments.aspx about the right process how to rename database

     

    You are welcome to share your migration tricks which saved your time

     

    Mirror: SharePoint 2007 migration tips

    September 07

    Farewell to TechEd 2008, Sydney

    Teched 2008 in Sydney finished. It were amazing 4 days of intensive sessions and parties afterwards.  I attended mostly all SharePoint session about infrastructure, governance and architecture, BizTalk sessions and ASP.NET MVC and LINQ session. The overall impression is high. Not all session were as good as I expected, but SharePoint once where just awesome - Joel Oleson and Michael Noel are just great. Really impressed.

    Got a lot of new info, which trying to sort now.

    The locknote was run by MS “futuronist” architect, describing how nowadays communication changes our life. The resume is that - expose everything to “services” and “context based devices” are  our future.

    Can’t wait the Tech-Ed 2009 in Goldcoast and expecting to deliver my SharePoint presentations at TechEd 2009.

    Mirror: Farewell to TechEd 2008, Sydney

    September 02

    Attending TechEd, Australia

    Going to attend the following TechEd sessions

    TechEdsessions

     

    Mirror: Attending TechEd, Australia

    SharePoint Infrastructure Update (WSS/MOSS) and exception with “Blocked file types” page

    After installing SharePoint 2008 (WSS/MOSS) Infrastructure Update from July 2008 you may find that “Blocked file types” page is broken (Central Administration –> Operations –> Blocked file types). Albeit it worked before, 10 mins ago, but now you end up with the following exception

    Object reference not set to an instance of an object.   at Microsoft.SharePoint.ApplicationPages.BlockedFileTypePage.InitializeValues()
       at Microsoft.SharePoint.ApplicationPages.BlockedFileTypePage.OnLoadComplete(EventArgs e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    What it means, that SharePoint can’t resolve your WebApplicationID (GUID of your site) from Content DB.

    The fully qualified URL for “Blocked file types” looks like “http://<CentralAdmin>:<port>/_admin/BlockedFileType.aspx?WebApplicationId=fa221a6a-42a2-4a09-8aac-76a31f160880”.

    I have no idea why SharePoint can’t resolve web application after Infrastructure Update, something wrong happened and your site just can’t be found. I didn’t test with SQL Profiler, but expect that nothing returning from Content DB

    To fix this you need just to create new Web Application :) That’s all. At this time the Content DB tables will be updated with new web app and GUID, and “Blocked file types” will start work again.

     

    Mirror: SharePoint Infrastructure Update (WSS/MOSS) and exception with “Blocked file types” page

    August 10

    Deploying SharePoint Web Parts as a part of PageLayouts in MOSS 2007

    Web Parts are an important and everywhere used part of SharePoint. Web Parts are documented pretty good and there are several sources describing as just ASP.NET WebParts (Darren Neimke book) and some resources about Web Parts in SharePoint as well. But in reality SharePoint WebPart specific stuff is not properly documented, and in this post I’d like to publish some tips regarding Web Parts in SharePoint

    General Info

    Not all Web Parts are inherited from System.Web.UI.WebControls.WebParts.WebPart class. Some of them comes from Microsoft.SharePoint.WebPartPages.WebPart, which is inherited from the System.Web.UI.WebControls.WebParts.WebPart now. When you develop your own Web Parts, in mostly cases you need to inherit from System.Web WebPart class

    Finding the connections

    For some tasks you might handle the Web Part connection/disconnection programmatically. For example, connect your Web Part via code or via Page Layouts. To do this you need to know the Consumer and Provider names. It’s not the problem for your Web Parts, but how to find the Provider name for the out-of-the-box Web Parts?! For this you need to use Reflector.

    First, to know the class name of SharePoint Web Part you need just put any Web Part to the page and export it to XML. In that XML you will find the assembly and class name.  After that open that assembly in Reflector and navigates to the class you need to get Provider name. Scrutinize that Web Part class to find the connections and name of Provider connection. Connection may be not exactly in that class, but in one of the base classes.

    For example for Page Filter Web Parts the Provider name is “ITransformableFilterValues

    Deploying Web Parts with connections

    If you deploy you pages and want to have Web Parts being already connected for each new page user creates, then you need to connect Web Part via XML description inside Page Layout.

    Connection consists from 3 parts:

    • Consumer ID and Name –which you know, because usually it’s you own custom Web Parts
    • Provider ID and Name – I described above how to extract that name
    • Name of the parameter you select from dialog box when connect Web Parts manually.

    So, let’s start:

    1. Put any Web Parts to your Page Layout (I use SharePoint Designer for this, because it simplify my work), save page and navigate to the code.
    2. In code find the <WebPartPages:WebPartZone> section, and there you will find you Web Parts markup tagged with <Components: prefix.
    3. Find the ProviderID attribute of the Web Parts you want to connect and remember values . These values will be used when we create the connection between Web Parts.
    4. Open your page in browser to verify it works.
    5. Connect Web Parts manually, and save the name of the parameter which is shown in the popup dialog box when you connect Web Parts
    6. Remove connections between Web Parts, and return back to SharePoint designer
    7. Open the Page Layout code and navigate to the very beginning of document. Try to find the following section “<WebPartPages:SPProxyWebPartManager”. If you don’t have this section you can miss the following step
    8. Add the <WebPartPages:SPProxyWebPartManager runat="server" ID="ProxyWebPartManager">  section inside “PlaceHolderMain” content holder
    9. Now, we are ready to create connections. Add the following codesnippet inside SPProxyWebPartManager
       1: <SPWebPartConnections>
       2:            <WebPartPages:SPWebPartConnection ID="g_myConnectionName"
       3:                ConsumerConnectionPointID="IFilterValues" ConsumerID="WebPartA"
       4:                ProviderConnectionPointID="ITransformableFilterValues" ProviderID="WebPartB">
       5:                <WebPartPages:TransformableFilterValuesToFilterValuesTransformer MappedConsumerParameterName="Parameter">
       6:                </WebPartPages:TransformableFilterValuesToFilterValuesTransformer>
       7:            </WebPartPages:SPWebPartConnection>
       8: </SPWebPartConnections>

          Let’s review the “blue” selections, because it’s where connection magic happens

      • g_myConnectionName is the name of current connection, can be any name
      • IFilterValues – Consumer interface name of Web Part which accept connection
      • WebPartA – consumer Web Part ID from the WebPartZone section we found and remembered previously
      • ITransformableFilterValues – Provider interface name of Web Part which provides connection (in this sample I used Page Filter web parts and they have such provider name. Refer to the “Finding the connections” section where I described how to extract the names
      • WebPartB – provider Web Part ID from the WebPartZone section we found and remembered previously
      • Parameter – the name from the connection dialog box where you select the parameter

    10.  Save the page layout. Go to SharePoint and create the new page based on that page layout. After page will be created you can find that your Web Parts are already connected. Job done!

    Take into account, that you can’t change Web Parts connection for pages created for the Page Layouts with predefined Web Part connections.

    Mirror: Deploying SharePoint Web Parts as a part of PageLayouts in MOSS 2007

    July 28

    ASP.NET Theme across all pages with XMLHttpRequest calls

    ASP.NET Themes is very powerful feature, but some limitations exist when you are trying to apply Themes dynamically.

    For the single page the way to apply theme is to use

    Page.Theme = “<themeName>”;

    inside  the OnPreInit event, but if you try to apply theme for all pages across your site you have two solutions:

    1. add this code to each of the pages
    2. apply theme for master.page – and it’s where problem starts

    ASP.NET master pages don’t support applying themes dynamically – only static support for the all site pages by setting attribute inside web.config.

    But what to do if you need control which theme to apply and you don’t want to add code to every page of your site?!

    The solution for this to create custom HttpModule, where apply theme for Page class inside PreRequestHandlerExecute event.

    See the following code-snippet of the ThemeHttpModule

       1: public void Init(HttpApplication context)
       2: {
       3:     context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
       4: }
       5:  
       6: void context_PreRequestHandlerExecute(object sender, EventArgs e)
       7: {
       8:     HttpContext context = HttpContext.Current;
       9:     if (!(context.Handler is Page))
      10:     {
      11:         return;
      12:     }
      13:  
      14:     Page page = (Page)context.Handler;
      15:     
      16:     if ((page != null))
      17:     {
      18:         string themeName = "Default";  // get theme name from somewhere
      19:         page.Theme = themeName;
      20:     }
      21: }

    Done. Now you have flexible control which theme to apply in realtime, extracting you theme names from config or from database.

    But there is one case, I’d like point you attention – XMLHttpRequest calls.

    If you have AJAX XMLHttpRequest direct calls - this code won’t work, because server returns you only portion of page, not the full page with header and body. And you can’t apply theme on partial pages.

    To solve this you need to check if it’s partial request or not, inside your HttpModule. In case of ASP.NET AJAX you could use ScriptManager.IsInAsyncPostBack, but for the direct XMLHttpRequest  calls you need to check the header for the Content-Type you are used when create the MSXML object.

    Something like this

       1: // Don't apply theme for XMLHttpRequest calls, because you are getting part of the page, not the full page
       2: if (! string.IsNullOrEmpty(context.Request.ContentType))
       3: {
       4:     return;
       5: }

    Now your themes will be applied only on pages, not the partial AJAX calls.

    Mirror: ASP.NET Theme across all pages with XMLHttpRequest calls

    July 09

    Moving ASP.NET master.page to SharePoint

    In these days SharePoint become more and more popular. There are number of web project which starts directly in SharePoint, but however a lot of project remains out the SharePoint scope, and exists as pure ASP.NET application.

    The one of the common task of migrating ASP.NET application to SharePoint is changing the site landing page to become SharePoint page. But it’s where the problem starts. ASP.NET applications tend to consume different modern tools and technologies like ASP.NET MVC, SilverLight, URL Rewriting and others which seems to be very common in pure ASP.NET development, but could be the potential problems in SharePoint world.

    There are three thing you need to concentrate on

    1) master.page

    • Remove AutoEventWireup="true" attribute. SharePoint doesn’t support it on all pages;
    • User controls are not supported on master.page, so move them to CONTROLTEMPLATES folder and change references
    • Check that all classes you inherit from has the namespaces

    2) CSS

    • SharePoint doesn’t support CSS validation on 100%, so I can hardly recommend something specific here. But what did helped me a lot id debuging and CSS customization is just to have the “clean” CSS file, which resets all customization http://meyerweb.com/eric/tools/css/reset/

    3) Web.config

    • You need to make sure that you are using the right siteMap defaultProvider (<siteMap section>) from your ASP.NET web.config, otherwise all your SiteMap elements will be considered as Sharepoint Publishing classes elements (if u have MOSS), which are differs from asp.net SiteMap classes
    • If you are using URL rewriting or other specific modules you need to create the <system.webServer> section in SharePoint config file and add them there.
    • You need to add all your DLLS to the list of SafeControls

    4) Code

    • You need to have [assembly: AllowPartiallyTrustedCallers()] in your dlls.
    • DLLs must be signed
    • All classes must have namespaces

     

    Mirror: http://msmvps.com/blogs/laflour/archive/2008/07/10/moving-asp-net-master-page-to-sharepoint.aspx

    July 02

    2008 MVP Award

    Hurray, got the 2008 MVP Award today! They re-awarded me again, since year 2005 in [.NET/C#] area for my achievements in “online consulting” ;)

    But this year I’m Australian MVP!

     

    Thinking about changing the area and become SharePoint MVP in the next year :)

    June 13

    SharePoint Designer removes tags when saves page layout - “file system” feature workaround

    In the current project we are using SharePoint Designer 2007 intensively to create number of PageLayouts, especially to put WebParts there and pre-configure WebParts connections. SPD is not such a bad tool, because there is no alternative for this. But time to time it really buggy and awful that you start thinking if it passed QA team before being released. (event SP1 doesn’t solve a lot of common crucial bugs, which stops you using SPD at all)

    The most disgusting stuff of SharePoint Designer is that it formats your pages markup without asking you. And what’s worse it REMOVES some tags. I really can’t understand that behaviour – WHY it removes what you typed when you save document?!

    Recently, we stumble over the very nasty thing of SPD – accidental formatting. We have a PageLayout with several web parts on the page and we created <SPWebPartConnections> section to predefine WebParts connections. But whenever you save your document, SPD for some reasons removes some of your <SPWebPartConnections>. We spent about 2 hours to understand any dependencies or logic, but without success. It seems that they have some kind of RAND which selects which of the SPWebPartConnections tags to remove. We tried to install several hotfixes for SPD – but nothing works.

    So, the only way is to use other tools, like Visual Studio. But there is a problem. If you are edit your pageLayout in Visual Studio and want to test it, you need to re-deploy your pagelayouts each time, because VS doesn’t support check-in/check-out to SharePoint Content DB.

    But there is alternative way to edit your pages and have check-in support from the Visual Studio. SharePoint has very cool “file system” feature. It means that you can navigate to your PageLayouts from explorer,  open them in any editor and save it back. All your changes will be stored in Content DB(!!)

    To do this your need to open Windows Explorer and navigate to My Network Places. On the left side you will see the “Add Network Places” item. Open it and type there “http://<yoursite>/_catalogs/masterpage/”, type the name of your network folder like “MySite PageLayouts” and press OK.

    Now, if you open the “MySite PageLayouts” item from Windows Explorer->My Network Places you will see the content of your “_catalogs/masterpage/” SharePoint folder. And now your can open your masterPage or PageLayouts in any editor, edit them and save them. All changes will be stored into ContentDB. But don’t forget to checkout your file before editing (via Sharepoint or SPD)

    So, this trick allows you to edit any SharePoint files and forget about SharePoint Designer issues

    Mirror: SharePoint Designer removes tags when saves page layout - “file system” feature workaround

    June 05

    Page events stop working after using output stream for binary download

    In my previous SharePoint projects I've met the situations when you need to outstreem some binary files, like PDF file or something else, but when you do this by the standard way (how you used to do in normal ASP.NET site) you found that page is "dead" after you streamed you file to the client. By "dead" I mean that it doesn't respond to any events, and you can't use this page.

    The problem lies in the SharePoint JavaScript files, which are integrated into the each web page, and seems that they protect you from unnecessary double-posts. But unfortunately such behaviour breaks your stream output.

    I didn't have a change to investigate this problem in details, to find out what exactly affects on this, and always solved this by putting stream out in the new popup window.

    In these days on SharePoint NGs this question was risen and "andyspears" posted a work-around, how to change the SharePoint JS and return the normal behaviour back.

       1: //1) Set your button's client-side click event to: 
       2: "exportRequested=true;" 
       3:  
       4: //2) register the following JS: 
       5: string beforeSubmitJS = "\nvar exportRequested = false; \n"; 
       6: beforeSubmitJS += "var beforeFormSubmitFunction = theForm.onsubmit; \n"; 
       7: beforeSubmitJS += "theForm.onsubmit = function(){ \n"; 
       8: beforeSubmitJS += "var returnVal = beforeFormSubmitFunction(); \n"; 
       9: beforeSubmitJS += "if(exportRequested && returnVal) 
      10:     {_spFormOnSubmitCalled=false; exportRequested=false;} \n"; 
      11:  
      12: //beforeSubmitJS += "alert(returnVal + '\\n' + _spFormOnSubmitCalled);"; 
      13: beforeSubmitJS += "return returnVal; \n"; 
      14: beforeSubmitJS += "}; \n"; 
      15:  
      16: //beforeSubmitJS += "alert(theForm.onsubmit);"; 
      17: this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alterFormSubmitEvent", beforeSubmitJS, true); 

    Thanks AdnySpears, good work!

    Mirror: Page events stop working after using output stream for binary download

    May 28

    Subclassing Content Query Web Part to override CAML query

    The Content Query Web Part (CQWP) in MOSS is one of the popular out-of-the-box Publishing components which is used in content management sites, allowing you to get results from different sources.

    But sometimes out of the box functionality is not enough to meet your requirements, and you need to customize CQWP. There are several resources describing how to do this - 1, 2, 3, 4

    The most important features which are missed in CQWP are:

    • overriding query to use custom CAML
    • enabling web-part connections

    To implement these functionality you need to subclass ContentByQueryWebPart class and override several methods.

    Below I will describe what exactly need to be done to achieve desired behaviour.

    Query Override

    To have custom CAML query in your Web part you need to override CreateChildControls base method. You can find samples how to do this in the references above, but it's done so implicitly, that you can easily spend hours to find out why you code doesn't work and gives you different errors

    The crucial part is in the way sending the query to the base class within overrided CreateChildControls

       1: protected override void CreateChildControls()
       2: {
       3:     this.QueryOverride = customQueryString;
       4:  
       5:     base.CreateChildControls();
       6:  
       7:     QueryOverride = string.Empty;
       8:  
       9:     CommonViewFields = string.Empty;
      10: }

    First, you need to set your custom query to the "this.QueryOverride" to inform base class about query - line 3

    Second, call base CreateChildControls() allowing your query being executed - line 5

    Third and last - CLEAN query and view fields properties - line 7,9. Without this step you will get errors when open your Web Part in edit mode

    Enabling Connection

    The Content Query WP doesn't accept any connections by default. You need to implement this too. Everything you need to to is just add ConnectionConsumer attribute. But trick in setting the right attribute which is used in Parameter dialog box, when you connect two web-parts.

       1: [ConnectionConsumer("Another WebPart", "IFilterValues", AllowsMultipleConnections = true)]
       2: public void SetConnectionInterface(IFilterValues filterProvider)
       3: {
       4:     if (filterProvider != null)
       5:     {
       6:         // save provider with values
       7:         providerValues = filterProvider.ParameterValues;
       8:         _filterProviders.Add(filterProvider);  // variable declaration is List<IFilterValues> _filterProviders = new List<IFilterValues>();
       9:         List<ConsumerParameter> parameters = new List<ConsumerParameter>();
      10:         
      11:         // add params
      12:         parameters.Add(new ConsumerParameter("param1",
      13:                 ConsumerParameterCapabilities.SupportsSingleValue |
      14:                 ConsumerParameterCapabilities.SupportsEmptyValue));
      15:         parameters.Add(new ConsumerParameter("param2",
      16:                 ConsumerParameterCapabilities.SupportsMultipleValues |
      17:                 ConsumerParameterCapabilities.SupportsAllValue |
      18:                 ConsumerParameterCapabilities.SupportsEmptyValue));
      19:  
      20:         filterProvider.SetConsumerParameters(new ReadOnlyCollection<ConsumerParameter>(parameters));
      21:  
      22:         }
      23: }

    Method name can be any, but pay attention which provider you are using . WebPart providers send data via different provider interfaces, for example when you are working with Filtering web parts (like "Current User Filter" web part) then you need to "listen" your incoming connections via IFilterValues (thx Mutaz for this findings), for other WB it could be IWebPartField or IWebPartRow.

    If you are expecting to get data from WP via unsupported provider you connection link will be dimmed

    Practical Sample

    @d2design kindly asked to provide practical sample, for example how to use current user as a keyword :)

    Actually, it's good example which shows how use both features I described.

    To do this you need to have:

    1. ShareServices (SSP) with UserProfile, where current userName is stored
    2. "Current User Filter" WebPart, to get the userName from SSP. It returns you logged user name by default (not necessary actually, as well as SSP, because you could resolve you user name via standard asp.net User class when construct custom query)
    3. Enable WebPart connections as I described above. You need to use IFilterValue interface for "Current User Filter" and store your incoming user name in variable.
    4. Override query to include your userName in resulted custom query.

     

    TIPS:

    1. When you are quering content which is not published and approved (like pages) you wont be able to see that content on the page in final view. You data will be available in page edit mode only, because they are treated as "draft" data.
    2. <OrderBy>CAML tag is not parsed by CQWP, you need to remove it from your query and set the related order field of CQWP class<OrderBy>CAML tag is not parsed by CQWP, you need to remove it from your query and set the related order field of CQWP class

     

    Mirror: Subclassing Content Query Web Part to override CAML query

    May 22

    MOSS Content Deployment Jobs - Lookup Fields and requirements

    Content Deployment Job is a nice feature of MOSS 2007 to secure your main site from unauthorized and accidental changes and have approved content being deployed via standard MOSS functionality.

    But Content Deployment Jobs are a bit tricky :(

    There are some areas which I'd like to highlight in the current post, which helps you to save hours in configuring Content Deployments Path and Jobs

     Requirements

    To have successful contend deployment you need to prepare your sites correctly. There is a great post from Stefan Gossner who provided detailed explanations to all pre-requirement.

    Just to summarize, you need:

    • Destination Site without any template pages (don't use "Blank" template even)
    • Deploy features to Source and Destination sites
    • Activate features ONLY on Destination site

     Incremental Deployment

    When you set deployment path and created your first job you need to do full deployment ("Deploy all content" option) first, and after it's done set the incremental deployment.

    Your incremental job could fail with the next exception

    "Violation of PRIMARY KEY constraint 'PK__#ExportObjects____50430BFC'. Cannot insert duplicate key in object 'dbo.#ExportObjects'."

    The reason is that SP1 for MOSS changed the document versioning system, but no changes where done to Content Deployment Job functionality. To solve this issue  you may need to install the following hotfix http://support.microsoft.com/kb/950279 or disable minor versioning for specific lists (google to find details about this)

     Lookup fields

    The biggest trick in Content Deployment Jobs relates to Lookup fields deployed via Feature. I think that the following exception will be familiar for those who tried run Content Deployment Jobs for Site with Lookup Fields feature

    The element 'FieldTemplate' in namespace 'urn:deployment-manifest-schema' has invalid child element 'Field' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'Field' in namespace 'urn:deployment-manifest-schema'. at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(ValidationEventHandler eventHandler, Object sender, XmlSchemaValidationException e, XmlSeverityType severity) at System.Xml.Schema.XmlSchemaValidator.ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, Object sender, String sourceUri, Int32 lineNo, Int32 linePos, Boolean getParticles) at System.Xml.Schema.XmlSchemaValidator.ValidateElementContext(XmlQualifiedName elementName, Boolean& invalidElementInContext) at System.Xml.Schema.XmlSchemaValidator.ValidateElement(String localName, String namespaceUri, XmlSchemaInfo schemaInfo, String xsiType, String xsiNil, String xsiSchemaLocation, String xsiNoNamespaceSchemaLocation) at System.Xml.XsdValidatingReader.ProcessElementEvent() at System.Xml.XsdValidatingReader.ProcessReaderEvent() at System.Xml.XsdValidatingReader.Read() at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject) at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader) at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects() at Microsoft.SharePoint.Deployment.SPImport.Run() 

    5/22/2008 11:14 AM Content deployment job 'Remote import job for job with sourceID = 0ffd575d-df2f-474f-83b6-f3454f2e7d0d' failed.The exception thrown was 'System.Xml.Schema.XmlSchemaValidationException' : 'The element 'FieldTemplate' in namespace 'urn:deployment-manifest-schema' has invalid child element 'Field' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'Field' in namespace 'urn:deployment-manifest-schema'.'

    The problems is exactly in deployment scripts of Lookup fields. There are several samples how to deploy lookup fields via feature (http://www.sharepointnutsandbolts.com/2007/04/feature-to-create-lookup-fields-on.html) but all of them are not suitable for the Content Deployment Jobs. Because you will get the exception which I posted above.

    The only way to find out why this happens is to use 3rd party tools (SharepointSpy or FieldsExplorer) to compare the SchemaXML of Lookup Fields after deployment via FeatureReceiver. So, after scrutinizing this issue I found out that deploying Lookup Fields via FeatureReceiver differs from Lookup fields create via Central Admin Web site. FeatureReceiver deployment adds additional attribute "xmlns="http://schemas.microsoft.com/sharepoint/" to the Lookup SchemaXML which breaks the Content Deployment Job.

    So, the solution is simple - verify the published schema in FeatureReceiver before calling Update() method for Lookup Field and remove this attribute.

     

    Mirror: MOSS Content Deployment Jobs - Lookup Fields and requirements