«

»

Nov 02 2010

Print this Post

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>

Permanent link to this article: http://sympmarc.com/2010/11/02/using-a-datasource-in-a-data-view-web-part-dvwp-in-a-different-site-in-sharepoint-designer-2010/

67 comments

3 pings

Skip to comment form

  1. Ben

    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

    1. Marc

      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.

      1. Ben

        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

        1. Marc

          Awesome. Glad to help.

          M.

          1. Athalis

            Hi Marc,

            can you update the blog post to remove also “__WebPartId” in the DVWP-header? I removed all parameters that had something to do with the list or web, but had not suspected the WebPartId responsible for my error.

            1. Marc

              Athalis:

              The __WebPartId attribute shouldn’t cause a problem unless you’ve got a duplicate value in two or more DVWPs in the page.

              M.

  2. Eric

    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!

  3. SharePoint Surfer

    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!

  4. Chris

    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…

  5. Mahmoud Algoul

    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.

    1. Marc

      Mahmoud:

      This should work exactly the same with any list (libraries are just lists). I’d check what you’ve typed again.

      M.

  6. Shannon D.

    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

  7. Bruce Musgrove

    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?

    1. Marc

      Bruce:

      I have not seen that. Can you explain your environment a bit more?

      M.

  8. Bruce Musgrove

    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.

  9. Bruce Musgrove

    I also discovered last night, that any time I use this method to add multiple web parts to a page, not matter how many, I have to remove all ListName and ListID from each DVWP’s WebPartPages:DataFormWebPart section before saving. If I fail to do this I will get errors when viewing the page.

    1. Marc

      Bruce:

      Sorry for the delayed reply.

      When you export a DVWP and then import it, there are a few other places in the DVWP where the list GUID can be stored. Sometimes there’s a ListName attribute in the header of the DVWP, for instance. I’ve always had the best luck simply creating the DVWP in the place where I want it to actually be. If I then need it elsewhere, I just copy the code out of the first page and paste it directly into the second page.

      All that said, I’ve never seen the ListID/ListName reversion that you’re describing.

      M.

  10. Anonymous

    Marc,

    Many thanks! I was struggling with this for almost a day before I found your post.

    1. Marc

      Glad I could help, Wendy!

      M.

  1. SharePoint 2010: Recopilatorio de enlaces interesantes (XIV)! « Pasión por la tecnología…

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

  2. SharePoint 2010: Recopilatorio de enlaces interesantes (XIV)! - Blog del CIIN

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

  3. Displaying Blog Posts in Different Sites in SharePoint 2010 » Marc D Anderson's Blog

    [...] need to add the WebURL parameter, as I describe in my older post Using a DataSource in a Data View Web Part (DVWP) in a Different Site in SharePoint Designer 2010. You should use the relative path to the blog site as the value. In my case, it’s [...]

Leave a Reply

%d bloggers like this: