SharePoint 2013: Show document library in different site
Steps
- 1) Open Document Library of Site A in SharePoint designer
- 2) Select the Document Library of Site A which is in XSLTListViewWebPart.
- 3) In Format Tab select either "to Site gallery" or "To File"and save the webpart.
- 4) Now close the SharePoint designer.
- 5) Open Site B and edit the page in Site B where you want to display the web part.
- 6) Click on "Add Web-part".
- 7) In Web part , click on "upload web part" and add the exported web part from site A.
- 8)Once you upload the webpart, you will see the uploaded web part in web part categories "Imported Web part"
- 9) Add this web part in page.
- 10) Once You add the webpart and publish the page and try to open the office documents that are available in webpart, you will get server error due to office web app which is used in Sharepoint 2013. As per url "
<Site URL>/_layouts/15/WopiFrame.aspx?sourcedoc=<Doc URL>&action=default
" , <Doc URL> is actually the GUID of the document and we are taking url from Site A and adding it in Site B so document GUID will search document inside Site B and due to which we get server error.
Script
To Resolve the issue we need to add below script in script editor webpart in same page.
Below script actually take the whole document url which is from Site A and open in new Tab.
<script>
function OnClickLink(t)
{
window.open(t+"?Web=1");
}
$(document).ready(function(){
$("div .ms-vb").find($("a")).each(function(){
var t = $(this).attr("href");
$(this).attr("onclick","OnClickLink('" + t + "');return false;");
$(this).attr("onmousedown","");
$(this).attr("href","");
})
});
</script>
Note: If required kindly change the WebID in webpart. By Default the webID ="00000000-0000-0000-0000-000000000000"
To find the WebID, Go To Settings-->Site Settings-->Content and structure-->from menu select --> site settings again.
In Url you will get SPWeb starts and ends with "%3A". Remove "%3A"