List out All Views for a SharePoint List


  public void RetrieveViews()
        {
            try
            {
                using (SPSite osite = new SPSite("SiteURL") )
                {
                    using (SPWeb oweb = osite.OpenWeb())
                    {
                        SPList olist = oweb.Lists[ListName];
                        if (olist != null)
                        {
                            SPViewCollection oviewCollection = olist.Views;
                            foreach (SPView oview in oviewCollection)
                            {
                                ComboBox1.Items.Add(oview.Title);  
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("RetrieveViews() "+ex.Message);
            }

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell