Exemplo n.º 1
0
        private void btnAddViewToFavorites_Click(object sender, EventArgs e)
        {
            SPView view = (SPView)cboViews.SelectedItem;

            FavoriteView fv = new FavoriteView(view.Url,view.ParentList.ParentWeb.ServerRelativeUrl);
            ActionCopyViewUtil.FavoriteViews.Add(fv);
            ActionCopyViewUtil.SaveFavoriteViews();
            ActionCopyView.DefInstance.PopulateFavoriteViews();
            ActionCopyView.DefInstance.cboFavoriteViews.SelectedIndex = ActionCopyView.DefInstance.cboFavoriteViews.FindStringExact(fv.ToString());
            this.Close();
        }
        private void btnAddViewToFavorites_Click(object sender, EventArgs e)
        {
            SPView view = (SPView)cboViews.SelectedItem;

            FavoriteView fv = new FavoriteView(view.Url, view.ParentList.ParentWeb.ServerRelativeUrl);

            ActionCopyViewUtil.FavoriteViews.Add(fv);
            ActionCopyViewUtil.SaveFavoriteViews();
            ActionCopyView.DefInstance.PopulateFavoriteViews();
            ActionCopyView.DefInstance.cboFavoriteViews.SelectedIndex = ActionCopyView.DefInstance.cboFavoriteViews.FindStringExact(fv.ToString());
            this.Close();
        }
Exemplo n.º 3
0
        private void lnkRemove_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (cboFavoriteViews.SelectedItem == null)
            {
                return;
            }
            FavoriteView fv = (FavoriteView)cboFavoriteViews.SelectedItem;

            ActionCopyViewUtil.FavoriteViews.Remove(fv);
            ActionCopyViewUtil.SaveFavoriteViews();

            ActionCopyView.DefInstance.PopulateFavoriteViews();
        }
Exemplo n.º 4
0
 internal static void LoadFavoriteViews()
 {
     FavoriteViews = new List<FavoriteView>();
     try
     {
         for (int i = 0; i <= GlobalVars.SETTINGS.createViews_viewUrls.Count - 1; i++)
         {
             FavoriteView fv = new FavoriteView(GlobalVars.SETTINGS.createViews_viewUrls[i], GlobalVars.SETTINGS.createViews_viewWebs[i]);
             FavoriteViews.Add(fv);
         }
     }
     catch (Exception ex)
     {
         Eh.GlobalErrorHandler(ex, "problem while Loading Favorite Views for 'Copy A View' ");
     }
 }
Exemplo n.º 5
0
 internal static void LoadFavoriteViews()
 {
     FavoriteViews = new List <FavoriteView>();
     try
     {
         for (int i = 0; i <= GlobalVars.SETTINGS.createViews_viewUrls.Count - 1; i++)
         {
             FavoriteView fv = new FavoriteView(GlobalVars.SETTINGS.createViews_viewUrls[i], GlobalVars.SETTINGS.createViews_viewWebs[i]);
             FavoriteViews.Add(fv);
         }
     }
     catch (Exception ex)
     {
         Eh.GlobalErrorHandler(ex, "problem while Loading Favorite Views for 'Copy A View' ");
     }
 }
Exemplo n.º 6
0
        private void createView(bool onlyValidate)
        {
            try
            {
                MainForm.DefInstance.Cursor = Cursors.WaitCursor;
                rtbDisplay.Clear();

                //--make sure that a favorite view has been selected and a target list
                if (cboFavoriteViews.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Favorite View\r\n", StyleType.bodyRed);
                    return;
                }
                if (cboTargetList.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Target List\r\n", StyleType.bodyRed);
                    return;
                }
                AddToRtbLocal("Copying A View" + Util.V(onlyValidate) + "\r\n", StyleType.titleSeagreen);

                //--initialize
                SPList       targetList = (SPList)cboTargetList.SelectedItem;
                FavoriteView fv         = (FavoriteView)cboFavoriteViews.SelectedItem;
                SPWeb        sourceWeb  = targetList.ParentWeb.Site.OpenWeb(fv.ParentWebURL);
                SPView       sourceView;
                try
                {
                    sourceView = sourceWeb.GetViewFromUrl(fv.ViewURL);
                }
                catch (Exception ex)
                {
                    AddToRtbLocal("Cannot find source view: \"" + fv.ViewURL + "\" " + ex.Message, StyleType.bodyRed);
                    return;
                }

                //--communicate with user
                AddToRtbLocal("View will be copied from ", StyleType.bodyChocolate); AddToRtbLocal(fv.ParentWebURL + "/" + fv.ViewURL + "\r\n", StyleType.bodyBlue);
                AddToRtbLocal("    to this SharePoint List: ", StyleType.bodyChocolate); AddToRtbLocal(targetList.RootFolder.ServerRelativeUrl, StyleType.bodyBlue);
                AddToRtbLocal(Util.V(onlyValidate) + "\r\n", StyleType.bodyChocolate);

                //--display details about view
                AddToRtbLocal("Source View Details\r\n", StyleType.bodyChocolateBold);
                string ags = Util.ToStr(sourceView.Aggregations);
                ags = (ags == "") ? "(none)" : ags;
                AddToRtbLocal("    Totals: " + ags + "\r\n", StyleType.bodyChocolate);

                string inFolders = sourceView.Scope.ToString();
                inFolders = inFolders.Replace("Default", "yes");
                inFolders = inFolders.Replace("Recursive", "no");
                AddToRtbLocal("    Show Items in Folders: " + inFolders + "\r\n", StyleType.bodyChocolate);

                AddToRtbLocal("    Item Limit: " + sourceView.RowLimit, StyleType.bodyChocolate);
                AddToRtbLocal((sourceView.Paged ? " (paging turned on)" : " (paging turned off)") + "\r\n", StyleType.bodyChocolate);

                //--check if view already exists, if it does delete it
                bool viewAlreadyExistsInTargetList = false;
                foreach (SPView view in targetList.Views)
                {
                    if (view.Title == sourceView.Title)
                    {
                        viewAlreadyExistsInTargetList = true;
                        if (!onlyValidate)
                        {
                            targetList.Views.Delete(view.ID);
                        }
                        break;
                    }
                }

                if (viewAlreadyExistsInTargetList)
                {
                    AddToRtbLocal("Note: ", StyleType.bodyChocolateBold);
                    AddToRtbLocal("View already exists in target library, deleting and recreating" + Util.V(onlyValidate) + "\r\n", StyleType.bodyChocolate);
                }

                //--verify that target library has all the fields needed in View.
                List <SourceViewField> sourceViewFields = new List <SourceViewField>();
                foreach (string viewFieldName in sourceView.ViewFields)
                {
                    sourceViewFields.Add(new SourceViewField(viewFieldName));
                }
                if (!VerifyAllViewFieldsFoundInTargetList(targetList, sourceViewFields))
                {
                    //if (!onlyValidate)
                    //{
                    //    DialogResult ret = MessageBox.Show(this, "Not all view fields exist in target list, would you like to create the view anyway?", "SUSHI - Copy a View", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    //    if (ret == DialogResult.No)
                    //        return;
                    //}
                    AddToRtbLocal("Note: ", StyleType.bodyChocolateBold);
                    AddToRtbLocal("Not all fields exist in target List, only fields from the source view that exist in the target list will be included in the new view.\r\n", StyleType.bodyChocolate);
                }


                //--copy view into target list
                if (!onlyValidate)
                {
                    SPView newView = targetList.Views.Add(sourceView.Title, ToStringCol(sourceViewFields), sourceView.Query, sourceView.RowLimit, sourceView.Paged, true);
                    newView.Aggregations       = sourceView.Aggregations;
                    newView.AggregationsStatus = sourceView.AggregationsStatus;
                    newView.Scope = sourceView.Scope;
                    newView.Update();
                    AddToRtbLocal("View created successfully.\r\n", StyleType.titleSeagreen);
                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("cancelled by user\r\n", StyleType.bodyRed);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
                MainForm.DefInstance.Cursor = Cursors.Default;
            }
        }