Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds


  Asked By: Hannah    Date: Jun 08    Category: Sharepoint    Views: 1126

I need to use a LinkViewWebPart for displaying links of a LinkWebPart
already existing in portal.
I wrote a custom webpart for this which a new LinkViewWebPart, and
linked it to existing linkwebpart through following code

ListsNew.ListName = listExisting.ID.ToString("B").ToUpper()
ListsNew.ViewGuid = listExisting.Views(0).ID.ToString("B").ToUpper()

but ti does not display the links from the link web part. What am I
doing wrong?
Are there any other properties I have to set??



3 Answers Found

Answer #1    Answered By: Gretchen Stokes     Answered On: Jun 08

This is a known issue with the OM - you cannot set  the view programmatically
based on another existing  view. The workaround is to instead use the
appropriate OM calls to change the individual properties  of the existing view.

Answer #2    Answered By: Angarika Shroff     Answered On: Jun 08

This might be a dumb question, but how do i do it? A small example
would be a great help.

Answer #3    Answered By: Eliza Hutchinson     Answered On: Jun 08

Here's a code snippet that should get you going in the right direction...

private bool AddDocLibView(SPWeb myWeb, SPDocumentLibrary dl)
bool retVal = false;
SPWebPartCollection wpc;
myWeb.AllowUnsafeUpdates =true;
string siteURL = myWeb.Url + "/default.aspx"
Microsoft.SharePoint.WebPartPages.ListViewWebPart lvwp = new ListViewWebPart();
lvwp.ZoneID = "Left"
lvwp.ListName = dl.ID.ToString("B").ToUpper();
wpc = myWeb.GetWebPartCollection(siteURL, Storage.Shared);
Guid wpG = wpc.Add(lvwp);
myWeb = SPControl.GetContextSite(Context).OpenWeb();
lvwp = (ListViewWebPart)wpc[wpG];
SPDocumentLibrary dl2 = (SPDocumentLibrary)myWeb.Lists[dl.ID];
SPView view = dl2.Views[new Guid(lvwp.ViewGuid)];
view.Query = "<Query><OrderBy><FieldRef Name=\"Last_x0020_Modified\"
Ascending=\"FALSE\" /></OrderBy></Query>"
view.RowLimit = 5;
retVal = true;

text += "<br>List view added"
catch(Exception ex)
text += "<br>" + ex.ToString();
retVal = false;
return retVal ;

Didn't find what you were looking for? Find more on LinkViewWebPart Or get search suggestion and latest updates.

Related Topics:



Related Post