/// <summary>
 /// Overrides base class event and adds custom code to remove items from
 /// My Submitted Documents list.
 /// Note. The protected OnClick_HtmlAnchorEnd() method is not virtual thus it won’t get called
 /// by the framework even if overriden.
 /// </summary>
 /// <param name="e"></param>
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     // Detect cancellation event
     if (Request.Form[EVENT_TARGET] != null && Request.Form[EVENT_TARGET].Contains("HtmlAnchorEnd"))
     {
         Guid guid = new Guid(base.StrGuidWorkflow);
         SPWorkflow workflow = new SPWorkflow(base.Web, guid);
         using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
         {
             SPList ObjList = SPContext.Current.Web.Lists[new Guid(Request.QueryString["List"].ToString())];
             SPListItem ObjItem = ObjList.Items.GetItemById(workflow.ItemId);
             ObjItem["Publishable Status"] = "";
             ObjItem.Update();
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// This Method handles CreateAppovalTask
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void CreateAppovalTask_MethodInvoking(object sender, EventArgs e)
        {
            string strApprovers = string.Empty;

            //Setting approvers for the document approval.
            SPSecurity.RunWithElevatedPrivileges(delegate()
             {

                 int _groupID = Convert.ToInt32(workflowProperties.Item["Document Approver"].ToString().Split(';')[0]);
                 using (SPWeb ObjRootWeb = SPHelper.GetRootWeb(SPHelper.GetRootUrl(workflowProperties.SiteUrl)))
                 {
                     SPGroup _approverGroup = ObjRootWeb.SiteGroups.GetByID(_groupID);
                     try
                     {
                         workflowProperties.Web.SiteGroups.Add(_approverGroup.Name, workflowProperties.Web.CurrentUser, null, _approverGroup.Description);
                     }
                     catch { }

                     foreach (SPUser user in _approverGroup.Users)
                     {
                         SPUser _user= workflowProperties.Web.EnsureUser(user.LoginName);
                         workflowProperties.Web.SiteGroups[_approverGroup.Name].AddUser(_user);
                     }
                     //SPFieldUserValue groupvalueGet = new SPFieldUserValue(group.ParentWeb, group.ID, group.Name);
                     CreateAppovalTask.TaskProperties.AssignedTo = _approverGroup.Name;
                 }
             });
            // Define a HybridDictionary object
            HybridDictionary permsCollection = new HybridDictionary();

            // Give Administrator rights to the user to whom the task has been assigned
            permsCollection.Add(CreateAppovalTask.TaskProperties.AssignedTo, SPRoleType.Administrator);

            // SpecialPermissions -the SpecialPermissions property  in your code will strip out all existing permissions inherited from
            // the parent list(Workflow Task List) and only adds permissions for each pair you added to the hashtable
            CreateAppovalTask.SpecialPermissions = permsCollection;

            //Setting the due date for approval
            CreateAppovalTask.TaskProperties.DueDate = DateTime.Now.AddDays(7);

            // Setting the title for the task
            CreateAppovalTask.TaskProperties.Title = workflowProperties.Item.Title;

            // Sending an Outlook Email and Outlook Task
            CreateAppovalTask.TaskProperties.SendEmailNotification = true;

            SPListItem ObjItem = workflowProperties.Item;
            using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
            {
                ObjItem["Publishable Status"] = "Awaiting for approval";
                ObjItem.SystemUpdate();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method updates approval Status
        /// </summary>
        /// <param name="ItemID">int</param>
        /// <param name="ListName">string</param>
        /// <param name="CurrentWeb">SPWeb</param>
        /// <param name="Status">string</param>
        private void UpdateApprovalStatus(int ItemID,string ListName,SPWeb CurrentWeb,string Status)
        {
            using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
            {
                CurrentWeb.AllowUnsafeUpdates = true;
                SPList list = CurrentWeb.Lists[ListName];
                SPListItem item = list.Items.GetItemById(ItemID);
                item["Publishable Status"] = Status;
                item.SystemUpdate();
                CurrentWeb.AllowUnsafeUpdates = false;
            }

            //Add Task Refs in the root site.
            using (DocumentApprovalTasks tasks = new DocumentApprovalTasks())
            {
                using (SPWeb ObjRootWeb = SPHelper.GetRootWeb(SPHelper.GetRootUrl(workflowProperties.SiteUrl)))
                {
                    tasks.UpdateTask(_documentApprovalTaskId, "Complete", ObjRootWeb);
                }
            }
        }
        public void btnYes_Clicked(Object sender, EventArgs e)
        {
            string _parentId = string.Empty;
            int _groupID = 0;
            lblMessage.Text = "";
            //SPFieldUserValue _approver = null;
            SPGroup _approverGroup=null;
            //Getting Publishing location details
            using (PublishableLocations ObjLocations = new PublishableLocations())
            {
                SPListItem _location = ObjLocations.GetPublishableLocationDetails(ddlPublishTo.SelectedValue);
                _groupID = Convert.ToInt32(_location["Document Approver"].ToString().Split(';')[0]);
                if (_location["Persistent ID"] != null)
                {
                    _parentId = _location["Persistent ID"].ToString();
                }
            }

            if (_parentId == string.Empty)
            {
                lblMessage.Text = "Sorry, cannot publish this document.<br/> publishable location 'Persistent ID' not set for this location, please contact your system administrator.";
                return;
            }
            //Check if Approval is Required
            if (rbtRequireApproval.SelectedValue == "1")
            {
                if (_groupID == null)
                {
                    lblMessage.Text = "Sorry, cannot publish this document.<br/> document approver(s) not set for this location, please contact your system administrator.";
                    return;
                }

                string siteUrl = SPControl.GetContextSite(Context).Url;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    _approverGroup = SPHelper.GetLandingWeb().SiteGroups.GetByID(_groupID);
                    using (SPSite ObjSite = new SPSite(siteUrl))
                    {
                        using (SPWeb ObjWeb = ObjSite.OpenWeb())
                        {
                            SPList ObjCurrentList = ObjWeb.Lists[new Guid(GetCurrentListID())];
                            SPListItem ObjItem = ObjCurrentList.Items.GetItemById(GetCurrentListItemID());
                            ObjWeb.AllowUnsafeUpdates = true;
                            using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
                            {

                                ObjItem["Publishable Status"] = "Awaiting for approval";
                                foreach (SPUser _approver in _approverGroup.Users)
                                {
                                    ObjWeb.EnsureUser(_approver.LoginName);

                                    //Assign approver read permission to this file
                                    SPHelper.AssignApproverReadPermission(ObjItem, _approver, ObjWeb);
                                    ObjWeb.AllowUnsafeUpdates = true;
                                }
                                //SPHelper.SetFieldValueUser(ObjItem, "Document Approver", _approver.LoginName);

                                SPFieldUserValue groupvalueGet = new SPFieldUserValue(_approverGroup.ParentWeb, _approverGroup.ID, _approverGroup.Name);
                                ObjItem["Document Approver"] = groupvalueGet;
                                ObjItem.Update();
                            }

                            //If Approval Required Activate the Workflow
                            ObjWeb.AllowUnsafeUpdates = true;
                            SPWorkflowManager objWorkflowManager = ObjItem.Web.Site.WorkflowManager;
                            SPWorkflowAssociationCollection objWorkflowAssociationCollection = ObjCurrentList.WorkflowAssociations;
                            foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection)
                            {
                                if (String.Compare(objWorkflowAssociation.BaseId.ToString("B"), "{51d62087-34c8-4a38-82d8-93ebe8f0c894}", true) == 0)
                                {
                                    WorkflowEventData eventData = new WorkflowEventData();
                                    eventData.Add("Publish_Location_ID", ddlPublishTo.SelectedValue);
                                    eventData.Add("Publish_Location_Name", ddlPublishTo.SelectedItem.Text);
                                    objWorkflowManager.StartWorkflow(ObjItem, objWorkflowAssociation, eventData.ToString(), true);
                                    break;
                                }
                            }
                            ObjWeb.AllowUnsafeUpdates = false;
                            ObjWeb.Update();
                        }
                    }
                });
            }
            else
            {
                //If Approval NOT Required Upload the file directly
                using (SPWeb ObjWeb = SPControl.GetContextWeb(Context))
                {

                    SPList ObjCurrentList = ObjWeb.Lists[new Guid(GetCurrentListID())];
                    SPListItem ObjItem = ObjCurrentList.Items.GetItemById(GetCurrentListItemID());

                    //Add file to the repository
                    SPHelper.AddItemToRepository(ObjWeb, ObjItem, _parentId);
                }
            }
            Response.Redirect(_sourceUrl);
        }
Exemplo n.º 5
0
 /// <summary>
 /// This method updates List item in the document library
 /// </summary>
 /// <param name="Item">SPListItem</param>
 /// <param name="Web">SPWeb</param>
 private static void UpdateSourceItem(SPListItem ObjItem, SPWeb Web, string PersistentId)
 {
     using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
     {
         Web.AllowUnsafeUpdates = true;
         ObjItem["Persistent ID"] = PersistentId;
         ObjItem["Publishable Status"] = "Copied to repository";
         ObjItem.Update();
         Web.Update();
         Web.AllowUnsafeUpdates = false;
     }
 }
Exemplo n.º 6
0
 private static void UpdatePublishedDocumentsLog(SPWeb Web, string _ObjectPID, SPListItem ObjItem)
 {
     using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
     {
         Web.AllowUnsafeUpdates = true;
         SPList list = Web.Lists["Published Documents"];
         SPListItem newItem = list.Items.Add();
         newItem["Title"] = ObjItem.Title;
         newItem["Published Date"] = DateTime.Now;
         newItem["Persistent ID"] = _ObjectPID;
         newItem["Content MimeType"] = ObjItem["Content MimeType"].ToString();
         newItem.Update();
         Web.Update();
         Web.AllowUnsafeUpdates = false;
     }
 }