ray1.net

Hi.

The below successfully adds a ListViewWebPart, but it does not set the view correctly.

I've debugged and plwp has the correct ViewGuid property, ListViewXml has the correct XML... but after I call AddWebPart it changes the guid.

plwp = new ListViewWebPart();
plwp.ZoneID = "Right";
plwp.ListName = playList.ID.ToString("B").ToUpper();
plwp.ViewGuid = playList.Views["Flash Fry"].ID.ToString("B").ToUpper();

//plwp.ViewGuid = playList.Views[0].ID.ToString("B").ToUpper();

//plwp.ViewGuid = playList.DefaultView.ID.ToString("B").ToUpper();

WebPartZoneCollection wpzc = wpm.Zones;
plwp.ExportMode = WebPartExportMode.All;


wpm.AddWebPart(plwp, wpzc[1], 0); //ViewGuid changes

plwp.ViewGuid = playList.Views["Flash Fry"].ID.ToString("B").ToUpper();

I've tried setting the ViewGuid after the ListViewWebPart has already been added to the page. I've tried ALL the examples out there and I've even tried using reflection and changing the property, which changes, but doesn't make ANY difference to the list.

The ListViewWebPart uses a random ViewGuid everytime.

The only thing left for me to do is change it directly in the DB, and we all know how MS love that.

Is it possible to programmatically change a ListViewWebPart view Show me pls.

protected void setCorrectMotherFuckingView()
{
web.AllowUnsafeUpdates = true;
SPWebPartCollection wpcWebParts = web.GetWebPartCollection(this.Page.Request.Url.ToString(), Storage.Shared);

foreach (Microsoft.SharePoint.WebPartPages.WebPart wptWebPart in wpcWebParts)
{
if (wptWebPart.GetType().ToString() == "Microsoft.SharePoint.WebPartPages.ListViewWebPart")
{
PropertyInfo[] pinProperties = wptWebPart.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo pinProperty in pinProperties)
{
//xx += pinProperty.Name;
if (pinProperty.Name == "ViewGuid")
{
string xx = pinProperty.GetValue(wptWebPart, null).ToString();
pinProperty.SetValue(wptWebPart, playList.Views["Flash Fry"].ID.ToString("B").ToUpper(), null);
wpcWebParts.SaveChanges(wptWebPart.StorageKey);
xx += pinProperty.GetValue(wptWebPart, null).ToString();
break;
}
}
}
}
}

Connecting webparts doesn't work either!

Thank you.



Re: SharePoint - Development and Programming ListViewWebPart change ViewGuid doesn't work.

Ponte83

Any news on this
Thanks