Re: Programatically Adding Document Library Webpart
From: Brad Smith [MVP] (asmodean_at_cox.net)
Date: 07/22/04
- Next message: VL: "Re: Is SharePoint suitable for dashboard/portal web-apps ?"
- Previous message: Si Pearson: "Re: Programatically Adding Document Library Webpart"
- In reply to: Si Pearson: "Re: Programatically Adding Document Library Webpart"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Jul 2004 17:25:33 -0400
It does sound like a bug, I'll look into it further and see if we are
missing something obvious.
-Brad
"Si Pearson" <SiPearson@discussions.microsoft.com> wrote in message
news:1269FB03-A8B2-4BB5-830F-CFBB3440FF76@microsoft.com...
> Brad,
>
> both, didn't work either way. For ages I thought it was some odd bug, the
code
> I was using worked fine in an external app to import pages, but as soon as
I put it into a webpart it just wouldn't work. It's really odd as I wrote
some code to check the list existed in the area I had context to and I could
see the one I wanted, but as soon as I tried to add it into a webpart page
in a doc lib in that area I got the error.
>
> I know what you were saying and I agree with it, but it just doesn't seem
to work.
>
> ta
>
> Si
>
> "Brad Smith [MVP]" wrote:
>
> > Si, did your list exist in a different area? Or did you have to do this
> > even when the list was in the current area context?
> >
> > -Brad
> >
> > "Si Pearson" <SiPearson@discussions.microsoft.com> wrote in message
> > news:8473C5D7-302B-448A-B7A8-3C8B141778B5@microsoft.com...
> > > Josh,
> > >
> > > I'm not sure Brad is right on this one. I had exactly the same
problem
> > and it was driving me mad, I knew the list exists, I could manually add
the
> > list where I wanted, I just not could not through code.
> > >
> > > I think the actual answer is that you need to set the ContextWeb to
the
> > area the list resides. If you don't do that you'll be looking for the
list
> > where Context is set, obviously it didn't exist there. What you need to
do
> > is this:
> > >
> > > *****
> > > SPWeb currentContextWeb = SPControl.GetContextWeb(Context);
> > > SPControl.SetContextWeb(Context, AREALISTINGEXISTS.Web);
> > > *****
> > >
> > > ListViewWebPart listViewWebPart = new ListViewWebPart();
> > >
> > > listViewWebPart.ZoneID = "Left";
> > > listViewWebPart.ListName = list.ID.ToString("B").ToUpper();
> > > listViewWebPart.ViewGuid = list.Views[0].ID.ToString("B").ToUpper();
> > >
> > > SPWebPartCollection webPartCollection =
> > > site.GetWebPartCollection("default.aspx", Storage.Shared);
> > >
> > > System.Guid guid = webPartCollection.Add(listViewWebPart);
> > >
> > > *****
> > > SPControl.SetContextWeb(Context, currentContextWeb);
> > > *****
> > >
> > > This worked for me after lots of messing around, so I hope it works
for
> > you.
> > >
> > > Let me know what happens.
> > >
> > > ta
> > >
> > > Simon
> > >
> > > "Brad Smith [MVP]" wrote:
> > >
> > > > It gives you this error because the webpart is not finding the list
that
> > you
> > > > provide via the listViewWebPart.ListName property. I would ensure
that
> > the
> > > > list name you provide is correct. Try assigning the SPList.Title
> > property
> > > > instead of the ID.
> > > >
> > > > -Brad
> > > >
> > > > "Josh S" <JoshS@discussions.microsoft.com> wrote in message
> > > > news:3737FE5A-227E-42C0-AE5E-8476A0BCF0A1@microsoft.com...
> > > > > Hi All
> > > > >
> > > > > I need to programatically add the Document library web part to the
> > > > default.aspx page.
> > > > >
> > > > > SPWeb site = SPControl.GetContextWeb(Context);
> > > > > SPList list = site.Lists["Document Library"];
> > > > >
> > > > > ListViewWebPart listViewWebPart = new ListViewWebPart();
> > > > >
> > > > > listViewWebPart.ZoneID = "Left";
> > > > > listViewWebPart.ListName = list.ID.ToString("B").ToUpper();
> > > > > listViewWebPart.ViewGuid =
list.Views[0].ID.ToString("B").ToUpper();
> > > > >
> > > > > SPWebPartCollection webPartCollection =
> > > > site.GetWebPartCollection("default.aspx", Storage.Shared);
> > > > >
> > > > > System.Guid guid = webPartCollection.Add(listViewWebPart);
> > > > >
> > > > > I tried this but it gives this error.
> > > > >
> > > > > List does not exist The page you selected contains a list that
does
> > not
> > > > exist. It may have been deleted by another user. Click "Home" at the
top
> > of
> > > > the page to return to your Web site., at
> > > > Microsoft.SharePoint.WebPartPages.ListViewWebPart.k() at
> > > > Microsoft.SharePoint.WebPartPages.ListViewWebPart.r() at
> > > > Microsoft.SharePoint.SPWebPartCollection.Add(ListViewWebPart
> > listWebPart)
> > > > >
> > > > > Though the document library exists, it throws the above error.
> > > > >
> > > > > I could add the Content viewer web part. but could not add the
doclib
> > > > webpart. Could anyone explain me whats the problem here. why does it
not
> > add
> > > > and why does it gives this strange error.
> > > > > Is there any limitations to this method.
> > > > >
> > > > > Thanks in Advance
> > > > > Josh
> > > >
> > > >
> > > >
> >
> >
> >
- Next message: VL: "Re: Is SharePoint suitable for dashboard/portal web-apps ?"
- Previous message: Si Pearson: "Re: Programatically Adding Document Library Webpart"
- In reply to: Si Pearson: "Re: Programatically Adding Document Library Webpart"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|