开发者

Get a List using its ID

I'm trying to get a list using it's ID, however it's not working and I can't work out why

This works without a problem...

using (SPSite site = new SPSite("http://example.org/sites/specific/staffhandbook"))
using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["Documents"];
        // process...
    }

So should this, but it 开发者_开发技巧doesn't?

using (SPSite site = new SPSite("http://example.org/sites/specific/staffhandbook"))
using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["29540646-bcab-4beb-8a91-648c1f3178b8"];
        // process...
    }


The SPListCollection accepts either an Int32 (an index), a String (the name of the list), or a Guid (the identifier), so the above, you'd need to do:

Guid guid = new Guid("29540646-bcab-4beb-8a91-648c1f3178b8");
SPList list = web.Lists[guid];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜