コード例 #1
0
 private void SaveTemporaryAttachment()
 {
     attachment.Update();
 }
コード例 #2
0
    /// <summary>
    /// Saves metadata and file name of attachment.
    /// </summary>
    /// <param name="newFileName">New attachment file name</param>
    /// <returns>Returns True if attachment was successfully saved.</returns>
    private bool SaveAttachment(string newFileName)
    {
        bool saved = false;

        // Save new data
        try
        {
            DocumentAttachment attachment = InfoObject as DocumentAttachment;

            if (attachment != null)
            {
                // Set new file name
                if (!string.IsNullOrEmpty(newFileName))
                {
                    string name = newFileName + attachment.AttachmentExtension;
                    attachment.AttachmentName = name;

                    if (!IsAttachmentNameUnique(attachment))
                    {
                        // Attachment already exists.
                        ShowError(GetString("img.errors.fileexists"));
                        return(false);
                    }
                }

                // Ensure automatic check-in/ check-out
                bool autoCheck = false;

                var wm = WorkflowManager.GetInstance(TreeProvider);

                if (!nodeIsParent && (Node != null))
                {
                    var wi = wm.GetNodeWorkflow(Node);
                    if (wi != null)
                    {
                        autoCheck = !wi.UseCheckInCheckOut(SiteName);
                    }

                    // Check out the document
                    if (autoCheck)
                    {
                        var nextStep = VersionManager.CheckOut(Node, Node.IsPublished);
                        VersionHistoryID = Node.DocumentCheckedOutVersionHistoryID;

                        if (IsWorkflowFinished(nextStep))
                        {
                            attachment = (DocumentAttachment)AttachmentInfo.Provider.Get(attachment.AttachmentGUID, SiteInfoProvider.GetSiteID(SiteName));
                        }
                    }
                }

                if (attachment != null)
                {
                    // Set filename title and description
                    attachment.AttachmentTitle       = ObjectTitle;
                    attachment.AttachmentDescription = ObjectDescription;

                    attachment.AllowPartialUpdate = true;

                    if (!nodeIsParent && (Node != null))
                    {
                        DocumentHelper.UpdateAttachment(Node, attachment);

                        // Check in the document
                        if (autoCheck)
                        {
                            if (VersionManager != null)
                            {
                                if (VersionHistoryID > 0 && (Node != null))
                                {
                                    VersionManager.CheckIn(Node, null);
                                }
                            }
                        }
                    }
                    else if (nodeIsParent)
                    {
                        attachment.Update();
                    }

                    saved = true;

                    string fullRefresh = "false";

                    if (autoCheck || (Node == null))
                    {
                        fullRefresh = "true";
                    }

                    // Refresh parent update panel
                    LtlScript.Text = ScriptHelper.GetScript("RefreshMetaData(" + ScriptHelper.GetString(ExternalControlID) + ", '" + fullRefresh + "', '" + attachment.AttachmentGUID + "', 'refresh')");
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(GetString("metadata.errors.processing"));
            Service.Resolve <IEventLogService>().LogException("Metadata editor", "SAVEATTACHMENT", ex);
        }

        return(saved);
    }