Click here to Skip to main content
15,891,431 members
Articles / Productivity Apps and Services / Sharepoint

Import List VS 2010 SharePoint Extension

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
27 Sep 2010CPOL11 min read 52.5K   658   12  
A Visual Studio 2010 SharePoint 2010 extension to import existing list definition and schema to SharePoint 2010 project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.SharePoint.Commands;
using Microsoft.SharePoint;

namespace Import_List_Implementation
{
    public static class Commands
    {
        public const string GetLists = "MANSoftDev.Commands.GetLists";
        public const string GetList = "MANSoftDev.Commands.GetList";
        public const string Test = "MANSoftDev.Commands.Test";
    }

    public static class SharePointCommands
    {
        [SharePointCommand(Commands.Test)]
        public static void Test(ISharePointCommandContext context, string siteUrl)
        {
            using(SPSite site = new SPSite(siteUrl))
            {

            }
        }

        [SharePointCommand("MANSoftDev.Commands.GetLists")]
        public static List<string> GetLists(ISharePointCommandContext context, string siteUrl)
        {
            List<string> lists = new List<string>();
            using(SPSite site = new SPSite(siteUrl))
            {
                using(SPWeb web = site.OpenWeb())
                {
                    foreach(SPList item in web.Lists)
                    {
                        lists.Add(item.Title);
                    }
                }
            }

            return lists;
        }

        [SharePointCommand(Commands.GetList)]
        public static SPList GetList(ISharePointCommandContext context, Tuple<string, string> info)
        {
            using(SPSite site = new SPSite(info.Item1))
            {
                using(SPWeb web = site.OpenWeb())
                {
                    return web.Lists.TryGetList(info.Item2);
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions