Example #1
0
        /// <summary>
        /// Override sharepoint save method.
        /// Create and temporary save a "create account request".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomSaveHandler(object sender, EventArgs e)
        {
            SPContext.Current.Web.AllowUnsafeUpdates = true;

            if (CurrentMode == SPControlMode.New)
            {
                CurrentItem[FieldsName.CategoryList.InternalName.CategoryID] = Guid.NewGuid();
            }

            //set category level
            if (!string.IsNullOrEmpty(ddlCategory.SelectedValue))
            {
                CurrentItem[FieldsName.CategoryList.InternalName.CategoryLevel] = Utilities.GetMenuLevel(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                                                         FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, FieldsName.CategoryList.InternalName.CategoryLevel);
            }
            //set category parent
            CurrentItem[FieldsName.CategoryList.InternalName.ParentID]   = ddlCategory.SelectedValue;
            CurrentItem[FieldsName.CategoryList.InternalName.ParentName] = Utilities.GetValueByField(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                                                     FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, "Text", FieldsName.CategoryList.InternalName.Title);
            //update category level for all children
            var newLevel = Utilities.ConvertToInt(Utilities.GetValueByField(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                            FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, "Text", FieldsName.CategoryList.InternalName.CategoryLevel)) + 1;

            if (CurrentMode.Equals(SPControlMode.Edit) && !newLevel.ToString().Equals(hidLevel.Value))
            {
                Utilities.UpdateChildrenLevel(CurrentWeb, ListsName.InternalName.CategoryList, FieldsName.CategoryList.InternalName.CategoryID,
                                              FieldsName.CategoryList.InternalName.ParentID, Convert.ToString(CurrentItem[FieldsName.CategoryList.InternalName.CategoryID]), newLevel + 1,
                                              FieldsName.CategoryList.InternalName.CategoryLevel);
            }
            //Save item to list
            SaveButton.SaveItem(SPContext.Current, false, string.Empty);
        }
Example #2
0
    public bool TrySaveItem(bool uploadMode, string comments)
    {
        bool saved = false;

        try
        {
            if (this.IsUploaded)
            {
                //The SaveButton has a static method called "SaveItem()" which you can use
                //to kick the whole save process into high gear. Just right-click the method
                //in Visuak Studio and select "Go to Definition" in the context menu to see
                //all of the juicy details.
                saved = SaveButton.SaveItem(this.ItemContext, uploadMode, comments);
                if (saved)
                {
                    this.OnItemSaved();
                }
            }
        }
        catch (Exception ex)
        {
            // do something
            throw ex;
        }
        finally
        {
        }
        return(saved);
    }
Example #3
0
        protected void CustomHandler(object sender, EventArgs e)
        {
            if (SaveButton.SaveItem(SPContext.Current, this.list.BaseTemplate == SPListTemplateType.DocumentLibrary, ""))
            {
                string sUrl = (List.ParentWeb.ServerRelativeUrl == ForwardSlash) ? "" : List.ParentWeb.ServerRelativeUrl;

                RedirectUrl = String.Concat(sUrl, ForwardSlash, List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, @"?ID=", ListItem.ID, @"&Source=", ListItem.ParentList.DefaultViewUrl);

                ProcessNewItemRecent(ListItem);
            }
            else
            {
                //We cannot check validations prior to SaveButton.SaveItem event - Because validation setting is set on List level!
                //this means SaveItem is unsuccessful - Let's check for validation settings for New and Edit form mode
                //If item won't saved due to some other reason then that thing is already handled in respective ItemAdding/ItemUpdating event and throws proper exception on screen.
                //Here, we have handled this special case for List Validation Settings because this page is inherit from ListFieldIterator class.
                if (mode == SPControlMode.New || mode == SPControlMode.Edit)
                {
                    if (!string.IsNullOrEmpty(list.ValidationFormula))
                    {
                        HtmlGenericControl divValidationErrorMessage = new HtmlGenericControl("div");
                        divValidationErrorMessage.InnerHtml = "<span id='Error_WPQ2ClientFormPlaceholder' class='ms-formvalidation ms-csrformvalidation'>" + list.ValidationMessage + "</span>";
                        this.Controls.Add(divValidationErrorMessage);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Handles save event for form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void FormSaveHandler(object sender, EventArgs args)
        {
            SPContext.Current.Item["Currency"]     = dropDownCurrency.SelectedValue;
            SPContext.Current.Item["DeliveryDate"] = dateTimeDeliveryDate.SelectedDate.ToString();

            SaveButton.SaveItem(SPContext.Current, false, String.Empty);
        }
Example #5
0
 /// <summary>
 /// Override sharepoint save method.
 /// Create and temporary save a "create account request".
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CustomSaveHandler(object sender, EventArgs e)
 {
     CurrentItem[FieldsName.ProfilesList.InternalName.CategoryId]   = ddlCategory.SelectedValue;
     CurrentItem[FieldsName.ProfilesList.InternalName.CategoryName] = Utilities.GetValueByField(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                                                FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, "Text", FieldsName.CategoryList.InternalName.Title);
     CurrentWeb.AllowUnsafeUpdates = true;
     SaveButton.SaveItem(SPContext.Current, false, string.Empty);
 }
        /// <summary>
        /// Handles save event for form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void FormSaveHandler(object sender, EventArgs args)
        {
            if (!ffldSalesOrderSclKey.Visible)
            {
                SPContext.Current.Item["SalesOrderSclKey"] = computedSalesOrderHeader.Text;
            }

            SaveButton.SaveItem(SPContext.Current, false, String.Empty);
        }
 /// <summary>
 /// Override sharepoint save method.
 /// Create and temporary save a "create account request".
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CustomSaveHandler(object sender, EventArgs e)
 {
     CurrentWeb.AllowUnsafeUpdates = true;
     if (CurrentMode.Equals(Constants.NewForm))
     {
         CurrentItem[FieldsName.ExternalNewsLink.InternalName.NewsGroup] = Request.QueryString["CatID"];
     }
     SaveButton.SaveItem(SPContext.Current, false, string.Empty);
 }
Example #8
0
 /// <summary>
 /// Override sharepoint save method.
 /// Create and temporary save a "create account request".
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CustomSaveHandler(object sender, EventArgs e)
 {
     if (fuFile.HasFile)
     {
         var    fuFileName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now), fuFile.FileName);
         SPFile file       = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuFile.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                            "{0}/{1}/{2}", WebUrl, ListsName.InternalName.AdvFileList, fuFileName));
         CurrentItem[FieldsName.AdvList.InternalName.AdvFile] = file.Url;
     }
     if (CurrentMode.Equals(Constants.NewForm))
     {
         CurrentItem[FieldsName.AdvList.InternalName.AdvID] = Guid.NewGuid();
     }
     CurrentWeb.AllowUnsafeUpdates = true;
     SaveButton.SaveItem(SPContext.Current, false, string.Empty);
 }
Example #9
0
        /// <summary>
        /// Override sharepoint save method.
        /// Create and temporary save a "create account request".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomSaveHandler(object sender, EventArgs e)
        {
            CurrentItem[FieldsName.ResourceLibrary.InternalName.CategoryId]   = ddlCategory.SelectedValue;
            CurrentItem[FieldsName.ResourceLibrary.InternalName.CategoryName] = Utilities.GetValueByField(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                                                          FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, "Text", FieldsName.CategoryList.InternalName.Title);
            CurrentWeb.AllowUnsafeUpdates = true;
            List <string> fileNames = new List <string>();

            if (fuImgThumb.HasFile)
            {
                var    fuThumbName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now), fuImgThumb.FileName);
                SPFile file        = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuImgThumb.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                                        "{0}/{1}/{2}", WebUrl, ListsName.InternalName.GalleryImagesList, fuThumbName));
                CurrentItem[FieldsName.ResourceLibrary.InternalName.ImgThumb] = file.Url;
                fileNames.Add(fuImgThumb.FileName);
            }
            if (fuFileUrl.HasFile)
            {
                var    fileUrl = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now), fuFileUrl.FileName);
                SPFile file    = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuFileUrl.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                                   "{0}/{1}/{2}", WebUrl, ListsName.InternalName.GalleryImagesList, fileUrl));
                CurrentItem[FieldsName.ResourceLibrary.InternalName.FileUrl] = file.Url;
                fileNames.Add(fuFileUrl.FileName);
            }



            CurrentWeb.AllowUnsafeUpdates = true;
            SaveButton.SaveItem(SPContext.Current, false, string.Empty);
            if (fileNames.Count > 0)
            {
                foreach (var fileName in fileNames)
                {
                    try
                    {
                        CurrentWeb.AllowUnsafeUpdates = true;
                        CurrentItem.Attachments.Delete(fileName);
                    }
                    catch (Exception ex)
                    {
                        Utilities.LogToULS(ex);
                    }
                }
                CurrentWeb.AllowUnsafeUpdates = true;
                CurrentItem.SystemUpdate(false);
            }
        }
Example #10
0
 protected void HandleNewItemRecent(object sender, EventArgs e)
 {
     if (SaveButton.SaveItem(SPContext.Current, this.list.BaseTemplate == SPListTemplateType.DocumentLibrary, ""))
     {
         ProcessNewItemRecent(SPContext.Current.ListItem);
     }
     else
     {
         //We cannot check validations prior to SaveButton.SaveItem event - Because validation setting is set on List level!
         //this means SaveItem is unsuccessful - Let's check for validation settings for New and Edit form mode
         //If item won't saved due to some other reason then that thing is already handled in respective ItemAdding/ItemUpdating event and throws proper exception on screen.
         //Here, we have handled this special case for List Validation Settings because this page is inherit from ListFieldIterator class.
         if (mode == SPControlMode.New || mode == SPControlMode.Edit)
         {
             if (!string.IsNullOrEmpty(list.ValidationFormula))
             {
                 HtmlGenericControl divValidationErrorMessage = new HtmlGenericControl("div");
                 divValidationErrorMessage.InnerHtml = "<span id='Error_WPQ2ClientFormPlaceholder' class='ms-formvalidation ms-csrformvalidation'>" + list.ValidationMessage + "</span>";
                 this.Controls.Add(divValidationErrorMessage);
             }
         }
     }
 }
Example #11
0
        private void onSave(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                try
                {
                    SaveButton      btnSave  = sender as SaveButton;
                    StringBuilder   sbErrors = new StringBuilder();
                    SPLongOperation longOp   = new SPLongOperation(this.Page);
                    longOp.LeadingHTML = "Please wait while the new case data is saved.";
                    longOp.Begin();
                    try
                    {
                        //SaveButton.SaveItem(btnSave.ItemContext, false, "");
                        bool isSaveSuccessful = false;
                        isSaveSuccessful = SaveButton.SaveItem(btnSave.ItemContext, false, "");
                        if (isSaveSuccessful == false)
                        {
                            sbErrors.Append("An error occurred.");
                        }
                    }
                    catch (SPException spex)
                    {
                        sbErrors.Append("An error occurred: " + spex.Message);
                    }
                    catch (Exception ex)
                    {
                        sbErrors.Append("An error occurred: " + ex.Message);
                    }

                    if (SPContext.Current.IsPopUI)
                    {
                        if (sbErrors.Length > 0)
                        {
                            sbErrors.Append("<br/><br/>Please <a href='#' onclick='history.go(-1);return false;'>go back</a> and try again.");
                            longOp.EndScript("document.getElementById('s4-simple-card-content').innerHTML = \"<br/>Errors have occurred during the submission. Details: <br/>" + sbErrors.ToString() + " \";");
                        }
                        else
                        {
                            longOp.EndScript("try { window.frameElement.commitPopup(); } catch (e) {}");
                        }
                    }
                    else
                    {
                        if (sbErrors.Length > 0)
                        {
                            SPUtility.TransferToErrorPage(sbErrors.ToString());
                        }
                        else
                        {
                            longOp.End(SPContext.Current.Web.Url, SPRedirectFlags.DoNotEndResponse | SPRedirectFlags.Trusted, HttpContext.Current, "");
                        }
                    }
                }
                catch (ThreadAbortException) { /* Thrown when redirected */ }
                catch (Exception ex)
                {
                    SPUtility.TransferToErrorPage(ex.ToString());
                }
            }
        }
Example #12
0
        /// <summary>
        /// Override sharepoint save method.
        /// Create and temporary save a "create account request".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomSaveHandler(object sender, EventArgs e)
        {
            List <string> fileNames = new List <string>();

            if (fuThumb.HasFile)
            {
                var    fuThumbName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now), fuThumb.FileName);
                SPFile file        = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuThumb.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                                     "{0}/{1}/{2}", WebUrl, ListsName.InternalName.NewsImagesList, fuThumbName));
                CurrentItem[FieldsName.NewsList.InternalName.ImageThumb] = file.Url;
                fileNames.Add(fuThumb.FileName);

                SPFieldUrlValue imgDsp = new SPFieldUrlValue();
                imgDsp.Description = CurrentItem.Title;
                var webUrl = CurrentWeb.ServerRelativeUrl;
                if (webUrl.Equals("/"))
                {
                    webUrl = "";
                }
                imgDsp.Url = webUrl + "/" + file.Url;
                CurrentItem[FieldsName.NewsList.InternalName.ImageDsp] = imgDsp;
            }
            if (fuSmallThumb.HasFile)
            {
                var    fuSmallThumbName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now.AddSeconds(1)), fuSmallThumb.FileName);
                SPFile file             = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuSmallThumb.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                                               "{0}/{1}/{2}", WebUrl, ListsName.InternalName.NewsImagesList, fuSmallThumbName));
                CurrentItem[FieldsName.NewsList.InternalName.ImageSmallThumb] = file.Url;
                fileNames.Add(fuSmallThumb.FileName);
            }
            if (fuSmallThumb.HasFile)
            {
                var    fuImageHotName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now.AddSeconds(1)), fuImageHot.FileName);
                SPFile file           = Utilities.UploadFileToDocumentLibrary(CurrentWeb, fuImageHot.PostedFile.InputStream, string.Format(CultureInfo.InvariantCulture,
                                                                                                                                           "{0}/{1}/{2}", WebUrl, ListsName.InternalName.NewsImagesList, fuImageHotName));
                CurrentItem[FieldsName.NewsList.InternalName.ImageHot] = file.Url;
                fileNames.Add(fuImageHot.FileName);
            }
            CurrentItem[FieldsName.NewsList.InternalName.NewsGroup]     = ddlCategory.SelectedValue;
            CurrentItem[FieldsName.NewsList.InternalName.NewsGroupName] = Utilities.GetValueByField(CurrentWeb, ListsName.InternalName.CategoryList,
                                                                                                    FieldsName.CategoryList.InternalName.CategoryID, ddlCategory.SelectedValue, "Text", FieldsName.CategoryList.InternalName.Title);

            CurrentWeb.AllowUnsafeUpdates = true;
            SaveButton.SaveItem(SPContext.Current, false, string.Empty);
            if (fileNames.Count > 0)
            {
                foreach (var fileName in fileNames)
                {
                    try
                    {
                        CurrentWeb.AllowUnsafeUpdates = true;
                        CurrentItem.Attachments.Delete(fileName);
                    }
                    catch (Exception ex)
                    {
                        Utilities.LogToULS(ex);
                    }
                }
                CurrentWeb.AllowUnsafeUpdates = true;
                CurrentItem.SystemUpdate(false);
            }
        }
Example #13
0
 /// <summary>
 /// CustomSaveHandler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void CustomSaveHandler(object sender, EventArgs e)
 {
     SPContext.Current.Web.AllowUnsafeUpdates = true;
     //Save item to list
     SaveButton.SaveItem(SPContext.Current, false, string.Empty);
 }
Example #14
0
        /// <summary>
        /// CustomSaveHandler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CustomSaveHandler(object sender, EventArgs e)
        {
            SPContext.Current.Web.AllowUnsafeUpdates = true;

            var item = SPContext.Current.ListItem;

            SPFieldLookupValueCollection returnVal = new SPFieldLookupValueCollection();

            foreach (ListItem lItem in ddlCat.Items)
            {
                if (lItem.Selected)
                {
                    if (lItem.Value != "0" && lItem.Text != "(None)")
                    {
                        returnVal.Add((new SPFieldLookupValue(
                                           int.Parse(lItem.Value), lItem.Text)));
                    }
                }
            }
            if (returnVal.Count > 0)
            {
                item[FieldsName.NewsRecord.English.CategoryName] = returnVal;
            }

            if (fuNewsImage.HasFile)
            {
                var webUrl = SPContext.Current.Web.ServerRelativeUrl;
                if (webUrl.Equals("/"))
                {
                    webUrl = "";
                }
                var    fuThumbName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Utilities.GetPreByTime(DateTime.Now), fuNewsImage.FileName);
                SPFile file        = Utilities.UploadFileToDocumentLibrary(SPContext.Current.Web, fuNewsImage.PostedFile.InputStream,
                                                                           string.Format(CultureInfo.InvariantCulture,
                                                                                         "{0}/{1}/{2}", webUrl, ListsName.English.ImagesList, fuThumbName));
                //CurrentItem[FieldsName.NewsList.InternalName.ImageThumb] = file.Url;
                RichImageField  rifImage   = new RichImageField();
                ImageFieldValue imageField = rifImage.Value as ImageFieldValue;
                if (imageField != null)
                {
                    imageField.ImageUrl         = webUrl + "/" + file.Url;
                    item["PublishingPageImage"] = imageField;
                }
            }

            //Save item to list
            SaveButton.SaveItem(SPContext.Current, false, string.Empty);

            try
            {
                if (fuNewsImage.HasFile)
                {
                    SPContext.Current.Web.AllowUnsafeUpdates = true;
                    item.Attachments.Delete(fuNewsImage.FileName);
                    SPContext.Current.Web.AllowUnsafeUpdates = true;
                    item.SystemUpdate(false);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogToUls(ex);
            }
        }