RE: Auto-update webpart property when object renamed

2012-02-05 Thread Brian Farnhill
The best way to go about this is to store the list ID for the list you need
to access. Have the setter property for ListName store the GUID into a
hidden property (still a public property, but without the web editable
attribute) so that the user still just chooses a list name, and then change
the getter for the property to look up the list name and return the string.
Then you can rename the lists in the UI as much as you like, but because you
are only ever working with the ID for it internally things shouldn't break

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

 

Hi all,

Is there a way to auto-update wp properties (such as list name) when the
object is renamed? I know SharePoint manages to do this with Summary Links
wp and the PageContent placeholder.

Kind regards,

Paul

 

___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


RE: Auto-update webpart property when object renamed

2012-02-05 Thread Paul Noone
Ah, of course. :)
Thanks!
From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Brian Farnhill
Sent: Monday, 6 February 2012 12:02 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

The best way to go about this is to store the list ID for the list you need to 
access. Have the setter property for ListName store the GUID into a hidden 
property (still a public property, but without the web editable attribute) so 
that the user still just chooses a list name, and then change the getter for 
the property to look up the list name and return the string. Then you can 
rename the lists in the UI as much as you like, but because you are only ever 
working with the ID for it internally things shouldn't break
Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter: @BrianFarnhillhttp://twitter.com/BrianFarnhill 
| blog: blog.brianfarnhill.comhttp://blog.brianfarnhill.com/ | xbox: Modern 
Boganhttp://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

Hi all,
Is there a way to auto-update wp properties (such as list name) when the object 
is renamed? I know SharePoint manages to do this with Summary Links wp and the 
PageContent placeholder.
Kind regards,

Paul

___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


RE: Auto-update webpart property when object renamed

2012-02-05 Thread Paul Noone
Hi Brian,
OK. I think I'm half way there. I've added a new private string for listID and 
a new property for ListID. I've attempted to modify the get/set part of the 
ListName property as you suggested but not sure if I'm on the right track.
Any assistance is greatly appreciated! :)
private string listID;
[WebPartStorage(Storage.Shared),
FriendlyName(The list name),
Category(Binding),
Browsable(false)]
public string ListName {
get
{
using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))
{
foreach (SPList list in SPContext.Current.Web.Lists)
{
listName = web.Lists[listID].Title.ToString();
}
}
return listName;
}
set
{
listName = value;
using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))
{
foreach (SPList list in SPContext.Current.Web.Lists)
{
listID = web.Lists[listName].ID.ToString();
}
}
}
}

[WebPartStorage(Storage.Shared),
FriendlyName(The list ID),
Category(Hidden),
Browsable(false)]
public string ListID
{
get { return listID; }
set { listID = value; }
}
From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Brian Farnhill
Sent: Monday, 6 February 2012 12:02 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

The best way to go about this is to store the list ID for the list you need to 
access. Have the setter property for ListName store the GUID into a hidden 
property (still a public property, but without the web editable attribute) so 
that the user still just chooses a list name, and then change the getter for 
the property to look up the list name and return the string. Then you can 
rename the lists in the UI as much as you like, but because you are only ever 
working with the ID for it internally things shouldn't break
Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter: @BrianFarnhillhttp://twitter.com/BrianFarnhill 
| blog: blog.brianfarnhill.comhttp://blog.brianfarnhill.com/ | xbox: Modern 
Boganhttp://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

Hi all,
Is there a way to auto-update wp properties (such as list name) when the object 
is renamed? I know SharePoint manages to do this with Summary Links wp and the 
PageContent placeholder.
Kind regards,

Paul

___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


RE: Auto-update webpart property when object renamed

2012-02-05 Thread Brian Farnhill
Of the top of my head, it should look something like this (I just bashed
this out in notepad, so you might need to tidy up any syntax errors and/or
typos)

[WebPartStorage(Storage.Shared)
FriendlyName(The list name),
Category(Binding),
Browsable(true)]
public string ListName {
 get
 {
   var list = SPContext.Current.Web.Lists[ListId];
   return list.Title;
 }
 set
 {
   var list = SPContext.Current.Web.Lists[value];
   ListId = list.ID;
 }
}

[WebPartStorage(Storage.Shared),
Browsable(false)]
public Guid ListId { get; set; }
private Guid _listId;

I would be putting some error handling around the getter and setter on list
name (what happens when ListID hasn't been set yet, what if they type in a
list name that doesn't exist, that sort of thing) but that is the basic idea
of how you could do it. Just refer to the list you need as
SPContext.Current.Web.Lists[ListId] and you should be fine.

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 1:45 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

Hi Brian,

OK. I think I'm half way there. I've added a new private string for listID
and a new property for ListID. I've attempted to modify the get/set part of
the ListName property as you suggested but not sure if I'm on the right
track.

Any assistance is greatly appreciated! J 

private string listID;

[WebPartStorage(Storage.Shared),

FriendlyName(The list name),

Category(Binding),

Browsable(false)]

public string ListName {

get

{

using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))

{

foreach (SPList list in SPContext.Current.Web.Lists)

{

listName = web.Lists[listID].Title.ToString();

}

}

return listName;

}

set

{

listName = value;

using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))

{

foreach (SPList list in SPContext.Current.Web.Lists)

{

listID = web.Lists[listName].ID.ToString();

}

}

}

}

 

[WebPartStorage(Storage.Shared),

FriendlyName(The list ID),

Category(Hidden),

Browsable(false)]

public string ListID

{

get { return listID; }

set { listID = value; }

}

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Brian Farnhill
Sent: Monday, 6 February 2012 12:02 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

The best way to go about this is to store the list ID for the list you need
to access. Have the setter property for ListName store the GUID into a
hidden property (still a public property, but without the web editable
attribute) so that the user still just chooses a list name, and then change
the getter for the property to look up the list name and return the string.
Then you can rename the lists in the UI as much as you like, but because you
are only ever working with the ID for it internally things shouldn't break

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

 

Hi all,

Is there a way to auto-update wp properties (such as list name) when the
object is renamed? I know SharePoint manages to do this with Summary Links
wp and the PageContent placeholder.

Kind regards,

Paul

 

___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


RE: Auto-update webpart property when object renamed

2012-02-05 Thread Paul Noone
Beautiful. Thanks again.
Yes on the error-checking. :)

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Brian Farnhill
Sent: Monday, 6 February 2012 1:56 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

Of the top of my head, it should look something like this (I just bashed this 
out in notepad, so you might need to tidy up any syntax errors and/or typos)
[WebPartStorage(Storage.Shared)
FriendlyName(The list name),
Category(Binding),
Browsable(true)]
public string ListName {
 get
 {
   var list = SPContext.Current.Web.Lists[ListId];
   return list.Title;
 }
 set
 {
   var list = SPContext.Current.Web.Lists[value];
   ListId = list.ID;
 }
}

[WebPartStorage(Storage.Shared),
Browsable(false)]
public Guid ListId { get; set; }
private Guid _listId;
I would be putting some error handling around the getter and setter on list 
name (what happens when ListID hasn't been set yet, what if they type in a list 
name that doesn't exist, that sort of thing) but that is the basic idea of how 
you could do it. Just refer to the list you need as 
SPContext.Current.Web.Lists[ListId] and you should be fine.
Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter: @BrianFarnhillhttp://twitter.com/BrianFarnhill 
| blog: blog.brianfarnhill.comhttp://blog.brianfarnhill.com/ | xbox: Modern 
Boganhttp://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Monday, 6 February 2012 1:45 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

Hi Brian,
OK. I think I'm half way there. I've added a new private string for listID and 
a new property for ListID. I've attempted to modify the get/set part of the 
ListName property as you suggested but not sure if I'm on the right track.
Any assistance is greatly appreciated! :)
private string listID;
[WebPartStorage(Storage.Shared),
FriendlyName(The list name),
Category(Binding),
Browsable(false)]
public string ListName {
get
{
using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))
{
foreach (SPList list in SPContext.Current.Web.Lists)
{
listName = web.Lists[listID].Title.ToString();
}
}
return listName;
}
set
{
listName = value;
using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))
{
foreach (SPList list in SPContext.Current.Web.Lists)
{
listID = web.Lists[listName].ID.ToString();
}
}
}
}

[WebPartStorage(Storage.Shared),
FriendlyName(The list ID),
Category(Hidden),
Browsable(false)]
public string ListID
{
get { return listID; }
set { listID = value; }
}
From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com 
[mailto:ozmoss-boun...@ozmoss.com]mailto:[mailto:ozmoss-boun...@ozmoss.com] 
On Behalf Of Brian Farnhill
Sent: Monday, 6 February 2012 12:02 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

The best way to go about this is to store the list ID for the list you need to 
access. Have the setter property for ListName store the GUID into a hidden 
property (still a public property, but without the web editable attribute) so 
that the user still just chooses a list name, and then change the getter for 
the property to look up the list name and return the string. Then you can 
rename the lists in the UI as much as you like, but because you are only ever 
working with the ID for it internally things shouldn't break
Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter: @BrianFarnhillhttp://twitter.com/BrianFarnhill 
| blog: blog.brianfarnhill.comhttp://blog.brianfarnhill.com/ | xbox: Modern 
Boganhttp://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan

From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com 
[mailto:ozmoss-boun...@ozmoss.com]mailto:[mailto:ozmoss-boun...@ozmoss.com] 
On Behalf Of Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.commailto:ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

Hi all,
Is there a way to auto-update wp properties (such as list name) when the object 
is renamed? I know SharePoint manages to do this with Summary Links wp and the 
PageContent placeholder.
Kind regards,

Paul

___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


RE: Auto-update webpart property when object renamed

2012-02-05 Thread Brian Farnhill
Just noticed you can also drop the line with the private _listId variable
too because I used the declarative getter/setter for that one, no need for
the private property in that case

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 1:59 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

Beautiful. Thanks again.

Yes on the error-checking. J

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Brian Farnhill
Sent: Monday, 6 February 2012 1:56 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

Of the top of my head, it should look something like this (I just bashed
this out in notepad, so you might need to tidy up any syntax errors and/or
typos)

[WebPartStorage(Storage.Shared)
FriendlyName(The list name),
Category(Binding),
Browsable(true)]
public string ListName {
 get
 {
   var list = SPContext.Current.Web.Lists[ListId];
   return list.Title;
 }
 set
 {
   var list = SPContext.Current.Web.Lists[value];
   ListId = list.ID;
 }
}

[WebPartStorage(Storage.Shared),
Browsable(false)]
public Guid ListId { get; set; }
private Guid _listId;

I would be putting some error handling around the getter and setter on list
name (what happens when ListID hasn't been set yet, what if they type in a
list name that doesn't exist, that sort of thing) but that is the basic idea
of how you could do it. Just refer to the list you need as
SPContext.Current.Web.Lists[ListId] and you should be fine.

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 1:45 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

Hi Brian,

OK. I think I'm half way there. I've added a new private string for listID
and a new property for ListID. I've attempted to modify the get/set part of
the ListName property as you suggested but not sure if I'm on the right
track.

Any assistance is greatly appreciated! J 

private string listID;

[WebPartStorage(Storage.Shared),

FriendlyName(The list name),

Category(Binding),

Browsable(false)]

public string ListName {

get

{

using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))

{

foreach (SPList list in SPContext.Current.Web.Lists)

{

listName = web.Lists[listID].Title.ToString();

}

}

return listName;

}

set

{

listName = value;

using (SPWeb web = SPContext.Current.Site.OpenWeb(WebId))

{

foreach (SPList list in SPContext.Current.Web.Lists)

{

listID = web.Lists[listName].ID.ToString();

}

}

}

}

 

[WebPartStorage(Storage.Shared),

FriendlyName(The list ID),

Category(Hidden),

Browsable(false)]

public string ListID

{

get { return listID; }

set { listID = value; }

}

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Brian Farnhill
Sent: Monday, 6 February 2012 12:02 PM
To: 'ozMOSS'
Subject: RE: Auto-update webpart property when object renamed

 

The best way to go about this is to store the list ID for the list you need
to access. Have the setter property for ListName store the GUID into a
hidden property (still a public property, but without the web editable
attribute) so that the user still just chooses a list name, and then change
the getter for the property to look up the list name and return the string.
Then you can rename the lists in the UI as much as you like, but because you
are only ever working with the ID for it internally things shouldn't break

Brian Farnhill
Solutions Architect, Extelligent Design | SharePoint Server MVP
phone: 0408 289 303 | twitter:  http://twitter.com/BrianFarnhill
@BrianFarnhill | blog:  http://blog.brianfarnhill.com/
blog.brianfarnhill.com | xbox:
http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan Modern
Bogan

 

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf
Of Paul Noone
Sent: Monday, 6 February 2012 11:58 AM
To: ozMOSS (ozmoss@ozmoss.com)
Subject: Auto-update webpart property when object renamed

 

Hi all,

Is there a way to auto-update wp