Skip to main content

Problem with RenderAsHtml in a cross site List web part

I have to display a view of a list, from the root web, in sus sites. I used the XsltListViewWebPart by adding the webpart in the galery of webparts by using SharePoint Designer (*).
This method doesn't work correctly, because i had to create sub sites using a template, where i inserted my XsltListViewWebPar. However, when i create a new site the view of my list is not the one i selected :(
So i decided to develop my own WebPart and use the RenderAsHtml method of my specific view. Every think was working correctly exept the sorting and filtering features and the contextual menu of items.
it shows the following message :



To solve that i found that i used to make this code :

                    SPList list = web.Lists[_list];

                    SPView viewInProgress = list.Views[_view];

                    String S = viewInProgress.RenderAsHtml();

                    String patern = "OnClick='javascript:SubmitFormPost\\(\".*\\?";

                    String substitution = "OnClick='javascript:SubmitFormPost(\"" +  SPContext.Current.Site.RootWeb.Url + "?";

                    S = Regex.Replace(S, patern, substitution);

                    writer.Write(viewInProgress.RenderAsHtml());


The problem was that the list wasn't in the same SPWeb.
Now, only the contextual menu isn't working ... I am working on ;)


Comments

Post a Comment

Popular posts from this blog

Updating SPListItem without triggering event receivers

I had an event receiver applied on documents wich can start, programatically of course, a workflow. In this workflow, i used to update some metadatas in my document item. However that triggers the event receiver a new time and you can imagine the infinate loop. Well! afeter googling i found that it is possible to diable the event firing just before the item.Update or the item.SystemUpdate. In first time i used this method but i didn't made my code in a try catch bloc. After doing that my workflow runs normally and it didn't fires the events in the event receiver. Here is the code : public static class SPListItemExtensions { /// /// Provides ability to update list item without firing event receiver. /// /// /// Disables firing  /// event receiver while updating item. public static void Update ( this SPListItem item , bool doNotFireEvents ) {     SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling ();     if ( doNotFireEven...

Printing ASPX HTML Forms

Here is the way to print a part of a HTML, ASPX Form    This is the content in the page to print <script language=JavaScript> <!-- function printPartOfPage(elementId) {  var printContent = document.getElementById(elementId);  var windowUrl = 'about:blank';  var uniqueName = new Date();  var windowName = 'Print' + uniqueName.getTime();  var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');  printWindow.document.write(printContent.innerHTML);  printWindow.document.close();  printWindow.focus();  printWindow.print();  printWindow.close(); } // --> </script> <div id="printDiv">  This is the content in the page to print </div> ////////////////////////// // To fire the event: ////////////////////////// <input type="button" value="Print" onclick="JavaScript:printPartOfPage('printDiv');" >

SharePoint Saturday France le 6 Nov. 2010

Rejoignez les architectes, les développeurs, les administrateurs, designers et autres professionnels qui travaillent avec SharePoint Server 2007 et SharePoint 2010 le 6 novembre 2010 pour un événement SharePoint exceptionnel. Les évènements SharePoint Saturday France sont des journées en libre accès, éducative, informative et animée, remplie de sessions de professionnels & MVPs reconnus pour leurs compétences et heureux de pouvoir partager leur expérience. Suivez-nous sur Twitter @clubsharepoint ou chacun des évènements sur le tag #SPSFrance. http://www.sharepointsaturday.com/france Facebook | SharePoint Saturday France