0

I have a document library set up on a sharepoint site that i need to display in a web part on another site page thats within the same domain, is this possible?

2
  • out of the box method or through code? by code i mean create a webpart with properties that call the list.
    – Ali Jafer
    Commented Aug 8, 2014 at 12:52
  • Im willing to try anything at the moment! Obviously out the box would be grand but as long as the code work isnt too heavy (not the greatest coder here) then im up for the challenge! Commented Aug 8, 2014 at 14:49

3 Answers 3

2

You can use PageViewer WebPart.

Create a page in the site having document Library and add the library as a WebPart. Now Create a page in destination site SP2007 and add PageViewer WebPart their. Give the link of page you earlier created having Library.

For details on how to add a PageViewer WebPart check this link

1
  • Thanks Varun, im going to have a read through this and see if its what im after. Ive come across some solutions that suggest using the page viewer web part and i tried it but it just displayed the whole page and not just the list items, from a quick glance at the link you shared it looks like there may be a way around that and if it works then ill be v happy! Commented Aug 8, 2014 at 14:51
0

create a webpart using visual studios... within the webpart class add custom properties

example:

namespace ExampleWebPart
{
    public class MyWebPart : WebPart
    {

        private string siteUrl = SPContext.Current.Site.Url;

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("custom settings"),
        WebDisplayName("Site url"),
        WebDescription("Add the url to the list in this textbox to connect to the external site list")]

       public string siteUrl 
       {
          get { return siteUrl; }
          set { siteUrl = value; }
       {

        private string listName = "Add List Name";

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("custom settings"),
        WebDisplayName("List Name"),
        WebDescription("Add the list name that you want to show")]

       public string listName 
       {
          get { return listName; }
          set { listName = value; }
       {

       protected override void CreateChildControls()
       {
          using (SPSite site = new SPSite(siteUrl))
          {
              using (SPWeb web = site.OpenWeb())
              {
                 SPList list = web.Lists[listName];
                 SPListItemCollection items = list.Items;

                 SPGrid oGrid = new SPGrid();
                 oGrid.DataSource = items.GetDataTable();
                 oGrid.DataBind();

                 this.Controls.Add(oGrid);
              }
         }
      }
    }
}

the above code might have some spelling mistakes ;) as I haven't tested it but I know it will work!

the code above, you create a webpart and within the .cs code you add the code above. The code first creates two properties that are added to the webpart chrome settings(when you edit the webpart, they will show up in the properties tab).

Next part we are adding the code to the createchildcontrols event, this is going to a specific site url that is pulled from the properties of the webpart and it then opens the web (site), within that site it looks for the list name that you want to get.... it then pulls the data from the list into a sharepoint gridview and binds the list to the grid.

Once we have the list and bound the list to the grid control we can then add it to the controls page so its viewable to the user.

That's pretty much it. let me know how you get on. The code should work and you should see an exact copy of the list within the webpart, the look and feel would be the same as the original list but only difference is that its within a webpart :)

how to display list items within a custom webpart to a grid

How to display list on application (aspx) page by visual studio?

creating a webpart:

http://www.codeproject.com/Articles/25019/Developing-SharePoint-WebParts

adding properties to a custom webpart:

http://sharepointsharpener.wordpress.com/2008/08/04/custom-properties-in-a-sharepoint-web-part/

and

http://msdn.microsoft.com/en-gb/library/dd584174(v=office.11).aspx

0

You can use WebPartPages:XsltListViewWebPart from

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

with code:

var view = web.TryGetView("listname");
var list = view.ParentList;
var web = list.ParentWeb;

webPart.Title = list.Title;
webPart.SPList(list);
webPart.ViewGuid = view.ID.ToString("B").ToUpper();

view = webPart.ContextView();
view.Scope = SPViewScope.Recursive;

var toolbar = webPart.ToolbarControl();

if (toolbar.Web.ID == web.ID && toolbar.Web.CurrentUser != null && toolbar.Web.CurrentUser.LoginName == web.CurrentUser.LoginName) return;

if (toolbar.Web.CurrentUser == null || !list.DoesUserHavePermissions(toolbar.Web.CurrentUser, SPBasePermissions.AddListItems))
    toolbar.TemplateName = "ToolBar";

toolbar.RenderContext = SPContext.GetContext(HttpContext.Current, webPart.ViewGuid.ToGuid(), webPart.ListId, web);

with some extensions

public static void SPList(this BaseXsltDataWebPart webPart, SPList value)
{
    var propertyInfo = webPart.GetType().GetProperty("SPList", BindingFlags.NonPublic | BindingFlags.Instance);

    propertyInfo.SetValue(webPart, value, null);
}

public static SPView ContextView(this BaseXsltListWebPart webPart)
{
    var propertyInfo = webPart.GetType().GetProperty("ContextView", BindingFlags.NonPublic | BindingFlags.Instance);

    return (SPView)propertyInfo.GetValue(webPart, null);
}

public static ViewToolBar ToolbarControl(this DataFormWebPart webPart)
{
    var propertyInfo = webPart.GetType().GetProperty("ToolbarControl", BindingFlags.NonPublic | BindingFlags.Instance);

    return (ViewToolBar)propertyInfo.GetValue(webPart, null);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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