Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Im having a problem placing the XsltListViewWebPart on my Default.aspx template (relevant code bellow)

<WebPartPages:WebPartZone runat="server" ID="NewsItemsList">
    <ZoneTemplate>
        <WebPartPages:XsltListViewWebPart AllowPartiallyTrustedCallers="TRUE" runat="server" ListUrl="Lists/NewsItemsListInstance" ID="NewsItems" DisplayName="" ChromeType="None" ViewGuid="{00000000-0000-0000-0000-000000000000}">
            <XmlDefinition>
                <View Name="MyView" Default="True" Type="HTML" Hidden="TRUE" TabularView="FALSE" DisplayName=" " Url="View.aspx" Level="255" BaseViewID="2" ContentTypeID="0x01000627D3E6EEDA4DCD9F403FE5F9A66E45" ImageUrl="/_layouts/images/generic.png">
                    <Query>
                    <OrderBy>
                        <FieldRef Ascending="FALSE" Name="ID"/>
                        <FieldRef Ascending="FALSE" Name="Callout"/>
                    </OrderBy>
                    </Query>
                    <ViewFields>
                        <FieldRef Name="Attachments"></FieldRef>
                        <FieldRef Name="LinkTitle"></FieldRef>
                        <FieldRef Name="Callout"></FieldRef>
                        <FieldRef Name="Icon"></FieldRef>
                    </ViewFields>
                    <RowLimit Paged="TRUE">6</RowLimit>
                    <Aggregations Value="Off"/>
                    <Toolbar Type="Standard"/>

                </View>
            </XmlDefinition>
            <XslLink>/Style Library/insight/xsl/NewsPortal.xslt</XslLink>
        </WebPartPages:XsltListViewWebPart>
    </ZoneTemplate>
</WebPartPages:WebPartZone>

when I browse to the template I receive the following error

Access denied. You do not have permission to perform this action or access this resource.

This only appears when i try to use the

<XslLink>/Style Library/insight/xsl/NewsPortal.xslt</XslLink>

element if I remove this then the error goes away. This has put me in a catch 22 situation because I can style the default view of the list through the schema.xml used to provision the list, however this styles all views of the list.

Is there even a way to specify this webpart to use a specific BaseViewID? if so what is it?

happy to provide more information if needed

Thanks in advance

Nicholas

UPDATE:

This is the ULS log error

Error while executing web part: System.UnauthorizedAccessException: <nativehr>0x80070005</nativehr><nativestack></nativestack>
at Microsoft.SharePoint.Library.SPRequest.UpdateWebPartCache(String bstrWebUrl, Boolean bAllUsers, String bstrID, Byte[]& ppsaData, Boolean fOMCall)
at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CacheWriteInternal(Guid storageKey, Byte[] cacheData, Storage storage, Boolean omCall)
at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.get_CustomizedXsl()
at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.LoadXslCompiledTransform(WSSXmlUrlResolver someXmlResolver)
at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()
at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)

UPDATE 2

I have checked the style library to see if the xsl is provisioned and i have discovered somthing that may be of use in solving this. In the GUI view the file does not exist to my user

Image of all content with file not existing

However if I type in the URL the file can be found.

Download box proving existance

Could this be what the webpart is complaining about? and if so how can i give the webpart access to the xslt?

Thanks

Nicholas

Update 3

I have tried using mapped folders to provision my XSL

and I can view the XSL through the browser ie browsing to the mapped folder.

<XslLink>/_layouts/xsl/newsportal.xsl</XslLink>

but the webpart generates this error in the browser

Access Denied. You do not have permission to perform this action or access this resource

I have done a bit of reading around and found that webpart security has been enhanced in sharepoint 2010 and have found the following link which are suggesting that the way forward is to edit the web.config.

http://msdn.microsoft.com/en-us/library/cc768613.aspx

however I struggle to believe this is the truly the case that I need to lower the security levels to just set a predefined property of the webpart (XslLink) can someone please confirm or deny that this is the case.

Thanks

Nicholas

Update 4

A bit more googling has yeilded the fact that there is indeed a "feature" in sharepoint 2010 xslt list view webpart in that an anon user cannot set the xsl or xsllink property.

http://stefan-stanev-sharepoint-blog.blogspot.co.uk/2010/08/xsltlistviewwebpart-several-xslt-tips.html

This has now brought me back full circle in that I need to provide a styled list view to users and also a traditional allItems.aspx view to editors where they can update the content of their list any suggestions greatly welcome as I am running out of ideas on this one :-S

Thanks

Nicholas

Update 5

Right I have carried on googling and cannot find a solution to this, I am however pretty confident that the collective mind of SO can. I am also convinced seeing the number of posts on various forums around the web that I am not the only person that has this issue.

http://www.google.co.uk/webhp?sourceid=chrome-instant&ie=UTF-8#hl=en&sclient=psy-ab&q=sharepoint+2010+xsltlistviewwebpart+access+denied&oq=sharepoint+2010+xsltlistviewwebpart+access+denied

So I am going to put this up for bounty as soon as I am aloud as I feel that the solution to this can benefit the sharepoint community.

share|improve this question
    
Tried escaping the URL by using %20 for Spaces, e.g. <XslLink>/Style%20Library/..... –  C. Marius - MVP Aug 7 '12 at 15:25
    
@C.Marius yes and it still doesn't work :-( but thank you for the suggestion. –  Nicholas King Aug 7 '12 at 15:32
add comment

3 Answers

up vote 5 down vote accepted

PROBLEM SOLVED :-) :-)

The bug of trying to set the xsllink property through the template seems to be a recognised bug. I'm even sure MS are aware of this as when looking at how they have created their site definitions it seems pretty uninstinctive.

The Solution

DO NOT SET OR DEFINE THE XSLTLISTVIEWWEBPART IN THE TEMPLATE

instead just define a webpart zone as shown.

<WebPartPages:WebPartZone runat="server" ID="NewsItemsList" />

IMPORTANT NOTE THE ID OF THE WEBPARTZONE(NewsItemsList) THIS IS REFERRED TO AS WEBPARTZONEID LATER ON

We can now define our view in the schema.xml of our list definition.

Schema.xml location

inside of schema.xml are a series of views with unique BaseViewId's.

<View BaseViewID="2" Type="HTML" Name="NewsStories2" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">NewsPortal.xsl</XslLink>
        <RowLimit Paged="TRUE">6</RowLimit>
        <ViewFields>
            <FieldRef Name="Attachments"></FieldRef>
            <FieldRef Name="LinkTitle"></FieldRef>
            <FieldRef Name="Callout"></FieldRef>
            <FieldRef Name="Icon"></FieldRef>
        </ViewFields>
        <Query>
            <OrderBy>
                <FieldRef Name="ID"></FieldRef>
            </OrderBy>
        </Query>
        <ParameterBindings>
            <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
            <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
  </View>

you can use the

<XslLink Default="TRUE">NewsPortal.xsl</XslLink>

property to set the location of the xsl in order to render the view.

All that is required now is placing the xsltlistview webpart inside of the template. This is done through the onet.xml.

onet.xml

<Module Name="DefaultBlank" Url="" Path="">
  <File Url="default.aspx">
      <View List="Lists/NewsItemsListInstance" BaseViewID="2" WebPartZoneID="NewsItemsList" WebPartOrder="1">
          <![CDATA[
                    <webParts>
                        <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                            <metaData>
                                <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" />
                                <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                            </metaData>
                            <data>
                                <properties>
                                    <property name="AllowConnect" type="bool">True</property>
                                    <property name="ChromeType" type="chrometype">None</property>
                                    <property name="AllowClose" type="bool">False</property>
                                </properties>
                            </data>
                        </webPart>
                    </webParts>
                ]]>
      </View>
  </File>
</Module>

IMPORTANT THINGS TO NOTE

on the view element.

according to the MS schema http://msdn.microsoft.com/en-us/library/ms438338.aspx

List = location of the list either integer or text(the texl url can be grabbed from the list instance elements.xml mine is shown below)

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="News Items List"
            OnQuickLaunch="TRUE"
            TemplateType="10001"
            Url="Lists/NewsItemsListInstance"
            <!--Feature ID Correlates to a user defined site scoped feature containing the list definition//-->
            FeatureId="599cdcf2-afdd-4ee8-a786-500554fc2b82"
            Description="My List Instance"
            >
  </ListInstance>
</Elements>

BaseViewId = The BaseViewId that you defined in the schema.xml and wish to use to render this view inside of the webpart.

WebPartZoneID = The Id property set on the webpartzone that is defined in the template where you wish for the xsltlistviewwebpart to be rendered.

I hope this answer helps someone as we have spent over a week trying to get this to work and it has essentially stopped all progress on our project. I hope to upload an image which hopefully will clarify the relationships between the sharepoint objects(xml files) more clearly.at a later time.

Thanks

Nicholas

Update

As promised here is an image illustrating how to provision the list, site definition and xsltlistviewwebpart successfully. No more 'Access denied' errors :-)

How to provision a site

share|improve this answer
add comment

Ok I'm going to kick off the answers with a potential answer which I don't really like but still.

http://social.msdn.microsoft.com/Forums/en-CA/sharepointdevelopment/thread/f7f3057d-5373-44e5-b040-743422781c2d

suggests that you can set the xsllink property through powershell however, this seems like a slight hack.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.WebPartPages") 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing") 


$spweb = Get-SPWeb "http://www.site.com"; 
$url = $spweb.Url; 
$WebPageUrl = "/Pages/test.aspx"
$spWpManager = $spweb.GetLimitedWebPartManager($WebPageUrl,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared); 
foreach($spwebpart in $spWpManager.Webparts) 
{ 
 $spwebpart.xsllink="_layouts/xsl/tony.xsl"; #set the web part property
 $spWpManager.SaveChanges($spwebpart);
} 

and I don't really feel all that comfortable proceeding with this approach. as it means writing a script to change the property of the xsllink in every instance of the xsltlistviewwebpart. Im hoping that a better solution is proposed, otherwise this may be the route that I go down.

Thanks

Nicholas

share|improve this answer
add comment

I ran into this issue. The problem seems to be XSL transform caching. Specifically anonymous / vs authenticated users.

An alternate solution is to add your xsl inline with the view. Just after the closing DataFields tag, add your XSL.

</DataFields>
<Xsl>
<!– Add your custom xsl here –>
</Xsl>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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