views:

57

answers:

2

I am creating a list with a deployed list template. with the following code:

SPSite site = new SPSite("http://servername");
SPWeb web = site.OpenWeb();

web.Lists.Add(listName, listName, listTemplate);
web.Update();
SPList List = Web.Lists[listName];

I am able to access the list with the web object which is used to create it. But, SPContext.Current.Web is not updated. So, the following throws error:

SPContext.Current.Web.Lists[listName]

Is it possible to update the SPContext.Current object with latest information so that the list accessible after it is created?

Thanks in advance!

Update: Code updated.

A: 

Your code doesn't show this, so I'm going to ask for the obvious: did you try calling web.Update() right after adding the new list?

Paul-Jan
Yes. I did that and got the same behavior. I've updated the question with this code.
Vijay
A: 

I added the below line after web.Update() and it started working.

SPContext myContext = SPContext.GetContext(Web);
Vijay