2

I have an XSLTListViewWebPart on an application page. Why I use visual studio to deploy it to the development site, it works fine, but when I use central administration to activate the feature on another site, and go to the application page, I get the error "the page you selected contains a list that does not exist."

Can anyone hint as to why this might be happening? I would paste in the web part code, but it's pretty long and I'm not sure it would be helpful.

I can confirm that the list I'm intending to use does exist on the site, but maybe I've got a relative reference to it that's not working properly, I guess. I just can't identify what property that might be. I've checked the TitleUrl ListID ListUrl and ViewGuid properties and they're all being set properly.

This is in 2010, but I'm not sure the issue is unique to 2010.

Edit: here's one of the web parts. There are actually three on the page, but they're all pretty basic and similar.

<WebPartPages:XsltListViewWebPart runat="server" Description="My List Instance" ListDisplayName="" PartOrder="2" HelpLink="" AllowRemove="True"
                        IsVisible="True" AllowHide="True" UseSQLDataSourcePaging="True" ExportControlledProperties="False" IsIncludedFilter="" DataSourceID=""
                        Title="Product Sequences" ViewFlag="8388621" NoDefaultStyle="" AllowConnect="True" FrameState="Normal" CatalogIconImageUrl="/_layouts/images/itgen.png"
                        PageSize="-1" PartImageLarge="/_layouts/images/itgen.png" AsyncRefresh="True" Dir="Default" DetailLink="{$SPUrl}/Lists/Product Sequences"
                        ShowWithSampleData="False" ListId="64592f39-d6ae-43d7-b580-4b2b72b350d2" ListName="{64592F39-D6AE-43D7-B580-4B2B72B350D2}" FrameType="Default"
                        PartImageSmall="" IsIncluded="True" SuppressWebPartChrome="False" AllowEdit="True" ViewGuid="{2D64D56A-4E74-4DE6-94BF-13183A7C378F}"
                        AutoRefresh="True" AutoRefreshInterval="3600" AllowMinimize="True" WebId="00000000-0000-0000-0000-000000000000" ViewContentTypeId="0x"
                        InitialAsyncDataFetch="False" GhostedXslLink="main.xsl" MissingAssembly="Cannot import this Web Part." HelpMode="Modeless" ListUrl=""
                        ID="ProductSequencesList" ConnectionID="00000000-0000-0000-0000-000000000000" AllowZoneChange="True" TitleUrl="{$SPUrl}/Lists/Product Sequences" ManualRefresh="True" __MarkupType="vsattributemarkup" __WebPartId="{2D64D56A-4E74-4DE6-94BF-13183A7C378F}" __AllowXSLTEditing="true" __designer:CustomXsl="fldtypes_Ratings.xsl" WebPart="true" Height="" Width="">
                        <ParameterBindings>
                    <ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
                    <ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
                    <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
                    <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
                    <ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" />
                    <ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" />
                    <ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" />
                    <ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" />
                    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
                    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
                        </ParameterBindings>
                        <XmlDefinition>
                    <View Name="{2D64D56A-4E74-4DE6-94BF-13183A7C378F}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="" Url="{$SPUrl}/SitePages/RecipeManagement.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">
                        <Query>
                            <OrderBy>
                                <FieldRef Name="ID"/>
                            </OrderBy>
                        </Query>
                        <ViewFields>
                            <FieldRef Name="Title"/>
                            <FieldRef Name="Vessel"/>
                            <FieldRef Name="Comments1"/>
                        </ViewFields>
                        <RowLimit Paged="TRUE">30</RowLimit>
                        <Toolbar Type="Freeform"/>
                    </View>
                        </XmlDefinition>
                        <DataFields>
                        </DataFields>
                    </WebPartPages:XsltListViewWebPart>

And Because the guids change each time it's deployed - I have this utility method, called from the code behind:

// in code behind (Page_Load):
Utilities.ResolveWebPartList("Product Sequences", ProductSequencesList);

the utility method:

internal static void ResolveWebPartList(string listName, XsltListViewWebPart listViewWebPart)
    {
        using (var site = new SPSite(SPContext.Current.Web.Url))
        using (var web = site.OpenWeb())
        {
            var theList = web.Lists[listName];
            if (theList == null)
            {
                throw new NullReferenceException(string.Format("The specified list '{0}' does not exist in the site '{1}'.", listName, SPContext.Current.Web.Url));
            }
            listViewWebPart.TitleUrl = theList.DefaultViewUrl;

            listViewWebPart.ListId = theList.ID;
            listViewWebPart.ListUrl = theList.DefaultViewUrl;
            listViewWebPart.ViewGuid = theList.DefaultView.ID.ToString();
        }
    }
  • could you add some code or something? – Remko Oct 31 '13 at 13:55
  • @Remko I said that I could post the web part markup, but it's long and I'm not sure it would be helpful. What part of the code would be helpful? – xdumaine Oct 31 '13 at 13:57
  • web.Lists[listName] results in an error when the list is not available better use web.TryGetList(listName). Do you deploy this as a module or? – Remko Oct 31 '13 at 15:02
  • Is List 64592F39-D6AE-43D7-B580-4B2B72B350D2 on your production site, or is that a development GUID? – Aron Foster Oct 31 '13 at 16:06
  • @Remko that code is working alright - it finds the list and gets the appropriate guids, etc. I actually want an error if the list doesn't exist. – xdumaine Oct 31 '13 at 18:12
1

I think your problem is in GUID formatting because

listViewWebPart.ViewGuid = theList.DefaultView.ID.ToString();

will format your view GUID like

00000000-0000-0000-0000-000000000000

and the GUID format should be

{00000000-0000-0000-0000-000000000000}

so you need to change your line to

listViewWebPart.ViewGuid = theList.DefaultView.ID.ToString("B");

Also take a look at this blog post: Programmatically create a SharePoint XsltListViewWebPart, with Cross-Site support

0

This answer may not fully apply as I was using a ListViewWebPart (not XsltListViewWebPart) but they are similar so it might help. The following code allowed me to use a ListViewWebPart from one site (with the embedded GUIDs in the source code) on a different site collection entirely:

listViewWebPart.ListId = theList.ID;
listViewWebPart.ViewGuid = theList.DefaultView.ID.ToString("B").ToUpper();
listViewWebPart.GetDesignTimeHtml();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.