/// <summary> /// This method copies file to the repository /// </summary> /// <param name="CurrentWeb">SPWeb</param> private void SubmitFileToRepository(SPWeb CurrentWeb) { string initiationData = workflowProperties.InitiationData; // Getting Publishbale Location ID var Publish_Location_ID = from _value in XElement.Load(new StringReader(EscapeXml(initiationData))).Elements("Publish_Location_ID") select _value; string _locationID = string.Empty; foreach (var ID in Publish_Location_ID) { _locationID = ID.Value; } string _locationPID = string.Empty; using (PublishableLocations ObjLocation = new PublishableLocations()) { _locationPID = ObjLocation.GetPublishableLocationPID(_locationID, workflowProperties.Web.Url); } //Publish this document to fedora SPHelper.SubmitItemToRepository(CurrentWeb, workflowProperties.Item, _locationPID); }
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); }
protected override void OnLoad(EventArgs e) { if (!IsPostBack) { using (PublishableLocations ObjLocations = new PublishableLocations()) { ddlPublishableLocations.Items.Clear(); SPListItemCollection items = ObjLocations.GetPublishableLocations(); foreach (SPListItem item in items) { ddlPublishableLocations.Items.Add(new ListItem(item.Title, item["Persistent ID"].ToString())); } if (Request.QueryString["rf"] != null) { _rootFolder=Request.QueryString["rf"].ToString(); ddlRoot.SelectedValue = _rootFolder; if (_rootFolder == "2") { ddlPublishableLocations.Visible = true; if (Request.QueryString["pid"] != null) { ddlPublishableLocations.SelectedValue = Request.QueryString["pid"].ToString(); } } else { ddlPublishableLocations.Visible = false; } } } } }
protected override void OnLoad(EventArgs e) { if (Request.QueryString["SourceURL"] != null) { _sourceUrl = Request.QueryString["SourceURL"].ToString(); } if (Request.QueryString["ID"] != null) { _itemId = Request.QueryString["ID"].ToString(); } if (Request.QueryString["List"] != null) { _listId = Request.QueryString["List"].ToString(); } if (!IsPostBack) { SPWeb ObjWeb = SPContext.Current.Web; // btnYes.PostBackUrl = ObjWeb.Site.Url + "/_layouts/CLIFPages/ClifSendFedora.aspx?ListId=" + _listId + "&ItemId=" + _itemId; SPList ObjList = ObjWeb.Lists[new Guid(_listId)]; SPListItem item = ObjList.Items.GetItemById(Convert.ToInt32(_itemId)); if (item.Workflows.Count == 0 ) { AttacheWorkflow(ObjWeb); lblMessage.Visible = false; btnYes.Enabled = true; } else { if (item.Workflows[item.Workflows.Count-1].InternalState==SPWorkflowState.Running) { lblMessage.Visible = true; lblMessage.Text = "Document approval request for publication already submitted."; btnYes.Enabled = false; } } lblTitle.Text = item.Title; lblContentSubject.Text = item["Content Subject"].ToString(); if (item["Content MimeType"] != null) { lblContentMimeType.Text = item["Content MimeType"].ToString(); } if (item["Persistent ID"] != null) { lblPersistentID.Text = item["Persistent ID"].ToString(); } else { lblPersistentID.Text = "(auto-generated)"; } //Populates all publication locations using (PublishableLocations ObjLocations = new PublishableLocations()) { SPListItemCollection _locations = ObjLocations.GetPublishableLocations(); int i = 0; foreach (SPListItem _location in _locations) { i++; ddlPublishTo.Items.Add(new ListItem(_location.Title, _location.ID.ToString())); } } } base.OnLoad(e); }