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>

77 Comments

  1. It doesn’t exist anymore, because it is now done through REST. You create a REST connection to any list or library in any site, site collection, web application, or farm. I’ve successfully exposed data in DVWPs from a completely separate farm and version of SharePoint. I took data from my SharePoint Foundation 2010 farm and exposed it in a web part page within my SharePoint Server 2010 farm by making a connection using REST, which is the preferred method now for connecting to other SharePoint content. SOAP can be used, too, but it can’t go across farms, although it can cross site collections. I have a full matrix of all the data source scenarios for each authentication type that will be published in our SharePoint Designer 2010 Unleashed book, which I think will be helpful to many.

    Reply
    • David:

      I’ve had horrible luck getting REST to work with DVWPs without passing credentials in the DVWP, which to me is a no-no. Do you have any tips or tricks on it?

      Because of the auth issue, I still feel that the “old” DVWP approach is preferable; it works the same as in 2007 and is reliable.

      M.

      Reply
  2. Marc,

    First of all, thank you for this post. There’s surprisingly little information about this out there, most everyone just accepts using SOAP or REST services to display list data from another subsite.

    With that said, I’m running into an issue when trying to implement this solution. I’ll walk through exactly what I’m doing, and I’m hoping you might have some advice for me.

    I’m editing a page, using SharePoint Designer, in the subsite where the list is located. I’m adding an empty Data View web part, and then selecting the list in question as the data source. Once it’s added, I’m copying the entirety of the web part code, and pasting it onto a page in the subsite where I want the Data View to display. Then I’m adding the “WebUrl” parameter as you’ve shown.

    Once that’s done, the web part shows up perfectly in design mode in SharePoint Designer, but when I try to view the page in a browser I get the following error:

    Web Part Error: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.

    I’d appreciate any help you can offer me with this. I’ve been fiddling around with various other parameters and settings, hoping to find something that works, and thusfar nothing has.

    Thanks again.

    Reply
    • Ben:

      My guess is that the path you are using in the WebURL is relative. It needs to be relative to the top level site. So, for instance, “/sites/mysite” as opposed to “../mysite”.

      M.

      Reply
  3. Marc, thanks for replying so quickly.

    Unfortunately, that is not the issue. I’m referencing the top level site, and the URL I’m using is “/”. I’ve also tried using “{sitecollectionroot}” as a placeholder, and got the exact same results. It worked in designer, but not in the browser.

    I am working on a publishing site, but as far as I’m aware that shouldn’t make a difference for data access.

    Thanks again for taking the time to answer my questions. I really appreciate any help you can offer

    Reply
    • Ben:

      So the list is in the root site and you’re trying to display it in a subsite? That should definitely work. Check the header of the DVWP (WebPartPages:DataFormWebPart) and make sure that the GUID for the list isn’t one of the attributes. Sometimes there is a ListID attribute, which you should delete.

      M.

      Reply
      • Marc, it’s working. You’re my personal hero today.

        There was no ListID attribute in the header, but there was a “__WebPartID=’{Guid}’” and once I removed that, it worked like a charm. Thank you again.

        Ben

        Reply
  4. I haven’t given this a shot yet (since we aren’t sure how we want to implement certain lists as either root collections or not) but looks to be a lifesaver if/when we decide to go that route!

    Definitely saved to my EverNotes!

    Reply
  5. the problem we had using REST is that it seems to hard code the full path then in a publishing site with content deployment in the deployed site the REST still references the original site. Thanks Marc this saved us!

    Reply
  6. List of the items that need to be modified using the line numbers in the sample code:

    Line 4 after the carriage return: DefaultValue=”Announcements”/ — Replace “Announcements” with your list name

    Line 5 after the carriage return: DefaultValue=”/Marc”/ — If the site with your list is “http://mysite.com/cars/steve” then your path will be “/cars/steve” – remove the “http://mysite.com” and use the rest.

    Replace those values I mentioned, use split view in SPD, click on your target DVWP and then replace all the code in between the “DataSources” tags.

    I struggled implementing this for about 30 minutes despite the fact that it *is* relatively simple… Ahh the life of a newb…

    Reply
  7. Cool article, it worked only for Lists, but for Document Library it is not.
    it gives below error:

    Web Part Error: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.

    any help please.

    Reply
  8. Hi Marc,
    You may have already found this by now, but what I did was create my dataview from the source site. Then I saved it to my site gallery web parts. I then was able to add it to my subsite by selecting it from the web part gallery. Seems to work perfectly!

    Shannon

    Reply
  9. This works great in SPD 2010, but whenever I check the page in, the ListId and ListName is automatically inserted and the DVWP breaks. I can not figure out how to stop it. Any ideas?

    Reply
  10. Can’t tell you much about the environment. I maintain my site collection on the server. The admins give us very little information about the server environment, except that is 2010 and on a farm. One farm is straight OOTB SharePoint. The other is a testing site, installed and configured differently, but I can’t get specifics. This may be because it was installed by a outside consulatant and the admins of that one do not even know what is different.

    I have deduced what is happening, but not why. It is frustrating because it does not make sense to me. I am a power user, just starting to get into digging into the code and i am sure that is a large part of why I do not understand.

    I need to add the same DVWP to the same page twice, each one filtered differently to display different data.

    1. Using SPD I created a DVWP on the parent site, and exported the DVWP to a file.

    2. I upload the DVWP to the child site in Pade edit mode ,and add it to the web page using page edit in the browser.as expected it throws a error.

    3. Open the page in SPD , make the necessary edits, save the file and it works in the browser.

    4. Close the page in SPD, check it in, and it still works in the browser.

    5. Repeated the stops to add it a second time. Make the required edits to the second DVWP in SPD. ListName and ListId have reappeared in the first DVWP. I do not touch them. Save the file and it works in the browser.

    6. Close the page in SPD, It still works in the browser.

    7. Check the page in from SPD, and it throws “List does not exist” errors.

    8. Open it in SPD, in both DVWP’s the ListId and Listname parameters have reappeared in both DVWP’s, in the WebPartPages:DataFormWebPart section. If I edit the DVWP’s, once again remove ListName and ListId, save the file and it still dows not work.

    9. delete theDVWP in SPD and save the page. Repeat the steps above except when I add the second DVWP, I edit the first DVWP to again remove Listname and ListId. save it, check it in and it works fine.

    The trick appears to again remove LitId and Listname from the 1st DVWP after the insertion of the second DVWP, and before I save the page.

    Another trick that seems to work; If I export two DVWP’s , each connected to the same list, but with different filters, everything works fine after you maek the necessary edits you suggested including removing the ListName and ListId.

    Reply

Leave a Reply