Using a DataSource in a Data View Web Part (DVWP) in a Different Site in SharePoint Designer 2010

For whatever reason, Microsoft in its infinite wisdom seems to have removed the ‘Connect to another library…’ link in the Data Source Library in SharePoint Designer 2010. Maybe that capability is hidden somewhere else now, but as my pal Chris Givens pointed out the other day in his Missing Features from SharePoint Designer 2010 post, it’s not “findable”.

Fortunately there’s a workaround and all of your 2007 Data View Web Parts (DVWPs) should work in 2010. (At least if this is the only issue!) You can simply add the same line into the DataSource that you would get if you used the ‘Connect to another library…’ link in 2007. The net-net in 2007 is that you end up with the WebPartPages:DataFormParameter named WebURL in your DataSource section. That’s the entire difference in the code if you want to access content in a different site: the WebURL parameter.  By setting that parameter to the relative URL of the site where the content resides, you can access content in any other site with a DVWP, just like in 2007. You just have to do it manually in the Code View.

Here’s an example of accessing an Announcements list from the root site in a SharePoint 2010 Site Collection which resides in a subsite called ‘Marc’. Note that I’ve also switched from ListID to ListName in this example. As long as your information architecture is solid, that switch can be useful to make your DVWP code more readable. It also can make your DVWP more portable to other sites or Site Collections.

<DataSources>
  <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" UseServerDataFormat="true" selectcommand="&lt;View&amp;gt;&lt;/View&gt;" id="dataformwebpart1">
    <SelectParameters>
      <WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Announcements"/>
      <WebPartPages:DataFormParameter Name="WebURL" ParameterKey="WebURL" PropertyName="ParameterValues" DefaultValue="/Marc"/>
    </SelectParameters>
  </SharePoint:SPDataSource>
</DataSources>

<UPDATE date=2012-05-07>

Note that you may also need to remove several attributes in the WebPartPages:DataFormWebPart header. If you are getting an error, check for attributes like this:

ListId="465831c5-3df1-4259-ba87-b9278007aba5" ListName="{465831C5-3DF1-4259-BA87-B9278007ABA5}"

and remove them. Removing these attributes won’t break the DVWP, and will fix the error.

</UPDATE>

Similar Posts

89 Comments

  1. Thanks for your reply!

    When you say “Build the DVWP in the blog site and then copy it into the parent site when you are finished,” do you mean insert the DVWP on the home page of the blog site and export the web part?

    I did that and tried to insert it on the home page on the main site and I got the “List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user” error.

    1. Shaun:

      You’d need to add the WebURL parameter for the DVWP to work when you move it to the other site. I never export/import; I just copy the code from one page to the other.

      M.

  2. Hi Mark …

    Im working with a dataview that bring information from 2 Different lists but i want use this dataview in other site where i have 2 list equals

    Site 1: List A , List B — Export
    Site 2: List A, List B — I need use de same Dataview werpart here also

    Could you help me? Do you have and choice to follow?

    Regards Thanks

      1. Im exporting the DV webpart and after i changed the ListId for List Name … then i received

        An unexpected error has occurred.

        Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.
        Troubleshoot issues with Windows SharePoint Services.

        my code is something like this:
        lt;/SelectParameters>
        <UpdateParameters>
        <asp:Parameter DefaultValue=”Autorizacion%20SAO” Name=”ListID”></asp:Parameter>
        </UpdateParameters>
        <InsertParameters>
        <asp:Parameter DefaultValue=”Autorizacion%20SAO” Name=”ListID”></asp:Parameter>
        </InsertParameters>
        <DeleteParameters>
        <asp:Parameter DefaultValue=”Autorizacion%20SAO” Name=”ListID”></asp:Parameter>
        </DeleteParameters>
        </sharepoint:SPDataSource>
        <sharepoint:SPDataSource runat=”server” DataSourceMode=”List” SelectCommand=”&lt;View&gt;&lt;/View&gt;” UpdateCommand=”” InsertCommand=”” DeleteCommand=”” UseInternalName=”True”><SelectParameters>
        <asp:Parameter DefaultValue=”Tasks” Name=”ListID”></asp:Parameter>
        </SelectParameters>
        <UpdateParameters>
        <asp:Parameter DefaultValue=”Tasks” Name=”ListID”></asp:Parameter>
        </UpdateParameters>

  3. Hi Mark … im here again :(

    I did it like ur suggest … and i have been received the same error … when i try to see web page in Browse mode

    An unexpected error has occurred.

    Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.
    Troubleshoot issues with Windows SharePoint Services.

    BUT in Sharepoint Designer Im watching the webpage correctly

    this part is from my code ….

        1. Perla:

          You posted a snippet of code, but didn’t give any context or ask any questions in your post on SharePoint StackExchange. That’s not a good use of the forum and makes it impossible for anyone to help you.

          M.

    1. Sarah:

      Given that in your case it’s a different subdomain, you may have other issues with authorization. You might need to use the Lists Web Service for your DataSource instead.

      First, though, try my approach. The WebURL goes in the DataSource’s SelectCommand.

      M.

  4. how would the defaultvalue for WebURL look if i want to go up one level from the current site url? ../ doesnt seem to work.

    Thanks,

    Joe

  5. thoughts?

    I was also considering using the server variable URL parameter, and for my defaultvalue of the webURL, setting it to the URL parameter. This, of course, would be the URL of the current site, but i dont know if i can do some XSL like string manipulation to the URL parameter…

      1. Thanks for the response… this is killing me – seems like it should be easy.

        I found this (it looks like you found it too), but i cant turn on the ASP code blocks in SharePoint pages (project restriction):

        http://stackoverflow.com/questions/609943/dynamically-set-the-defaultvalue-of-a-parameterbinding-in-a-dataformwebpart

        if only i could do some string manipulation to the asp text box text value without and asp code block…

        I am able to use xsl manipulation to set the text box text property to the correct value if i put the asp text box in another existing webpart on the page, but then i cant reference that text box as a control in my main webparts parameterbindings…

        My thought is to set a global xsl variable on the page, use that variable in the asp text box (outside of a webpart) and then consume that value in the parameter bindings… but i dont know how to make a global xsl variable (where to put it) and how to reference the servervariable(url) outside of a webpart…

  6. Marc,

    I’ve been trying to get this to work and I can get about 50% there and can’t figure out what I am missing. Your method works flawlessly within SPD and it renders in the previews, etc. However, when I publish and go to the page I get an error stating: “Web Part Error: An error has occurred.” where the DVWP should be displayed. Any ideas?

    1. Robert:

      Make sure that your WebURL is relative to the server, not the current site. For instance, this would be bad: “../../MySite”, but this would be good: “/MySite”.

      M.

  7. Marc

    I am getting a weird issue whereby I can happily either import or post the dvwp
    from to a page sitting on a subsite.

    The view renderers correctly

    I then renders correctly in my SPD preview pane. Go to preview in browser and there is a
    Web Part Error!

    Weird eh?

  8. Hi Marc,

    Can i export the data view data ( with multiple data source ) to excel? If yes please let me know how?

    Thanks
    Shilpa

      1. Hi Marc,

        Thanks for the quick reply.
        The requirement is to achieve it Out of the box(if possible or thru sharepoint designer).
        If i am not wrong, the export to excel option is available in standard toolbar of list but not sure whether this would be available in case of multiple list data view or not.
        I am still not finding anything related to this on net. :-(

        Thanks
        Shilpa

      2. Hi Marc,

        Thanks for the quick reply.
        The requirement is to achieve it Out of the box(if possible or thru sharepoint designer).
        If i am not wrong, the export to excel option is available in standard toolbar of list but not sure whether this would be available in case of multiple list data view or not.
        I am still not finding anything related to this on net. :-(

        Thanks
        Shilpa

  9. Hi,

    After importing sites from 2007 to 2010 while trying to insert a data view web part using SP Designer the sites lists and libraries do not show. For newly created sites in SP2010 it works fine. Any fixes for this issue?

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.