I noticed a weird behavior of the Sharepoint Object Model when trying to set the attributes of an existing list of a Sharepoint site.
The following code works as you expect:
spList = web.Lists[“MyList”];
spList.OnQuickLaunch=true;
spList.Update();
but not this one:
web.Lists[“MyList”].OnQuickLaunch=true;
web.Lists[“MyList”].Update();
It is a “by design” behavior even if most of you considered it a bug. I had to use the reflactor in order to demonstrate my affirmation.
The code statements that are important for us were highlighted.
The following code is the indexer implementation of the SPListCollection class (including the other methods used by the indexer):
public SPList this[string strListName]
{
get
{
return this.GetListByName(strListName, true);
}
}
internal SPList GetListByName(string strListName, bool bThrowException)
{
this.EnsureListsData(null);
int num = 0;
while (num < this.m_dwCount)
{
if (!SPUtility.StsCompareStrings(strListName, (string) this.m_arrListsData[(int) ((IntPtr) 4L), (int) ((IntPtr) num)]))
{
num++;
continue;
}
return this.CreateSPList((uint) num);
}
if (bThrowException)
{
throw new ArgumentException();
}
return null;
}
private SPList CreateSPList(uint index)
{
SPBaseType type2 = (SPBaseType) Convert.ToUInt32(this.m_arrListsData[8, index]);
if (type2 == SPBaseType.DocumentLibrary)
{
SPListTemplateType type = (SPListTemplateType) this.m_arrListsData[10, index];
switch (type)
{
case SPListTemplateType.PictureLibrary:
return new SPDocumentLibrary(this, this.m_arrListsData, index);
}
return new SPPictureLibrary(this, this.m_arrListsData, index);
}
if (type2 != SPBaseType.Issue)
{
return new SPList(this, this.m_arrListsData, index);
}
return new SPIssueList(this, this.m_arrListsData, index);
}
SPList class:
internal SPList(SPListCollection lists, object[,] arrListProps, uint iRow)
{
this.m_Lists = lists;
this.m_arrListProps = arrListProps;
this.m_iRow = iRow;
this.m_ListAttributesDict = new ListDictionary();
}
As you can see, the indexer creates a SPList every time the indexer is called.
If you analyze the non-working code again it will be clear enough:
A new SPList is created and its OnQuickLaunch property is set to true:
web.Lists[“MyList”].OnQuickLaunch=true;
A new SPList is created and the Update method is called, but nothing special happens because the OnQuickLaunch property was set on other SPList instance:
web.Lists[“MyList”].Update();
The same behavior was observed also when working with the DefaultView (please see my previous post about that). I’m convinced that this behavior is applicable as well to other sharepoint objects.


He also backs tightening border security and clamping down on employers that cheap prada hire undocumented workers.
He highlighted those points on Thursday, while saying the slow system of processing legal immigrants must be fixed, too.
What I wouldnt give to have a debate with you about this. You just say so many things that come from nowhere that Im pretty sure Id have a fair shot. Your blog is great visually, I mean people wont be bored. But others who can see past the videos and the layout wont be so impressed with your generic understanding of this topic.
Hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.
Wow, very interesting article. It’s funny how history can be twisted in so many different ways. These photos certainly give us clues, but I guess we’ll never know the true story. . . .
Advantageously, the post is actually the sweetest topic on this registry related issue. I fit in with your conclusions and will thirstily look forward to your future updates. Just saying thanks will not just be enough, for the extraordinary clarity in your writing. I will immediately grab your rss feed to stay informed of any updates.
This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
Majocka@about.com
Will i website link as much as this, through my own web page? I’m planning to gather as much sources of tips as i am able.