protected void ProcessFileUploader()
    {
        TreeNode node = DocumentManager.Node;

        // Create new document
        string fileName = Path.GetFileNameWithoutExtension(FileUpload.FileName);

        int maxFileNameLength = FileNameFieldInfo.Size;

        if (fileName.Length > maxFileNameLength)
        {
            fileName = fileName.Substring(0, maxFileNameLength);
        }

        node.DocumentName = fileName;
        if (node.ContainsColumn("FileDescription"))
        {
            node.SetValue("FileDescription", txtFileDescription.Text);
        }
        node.SetValue("FileAttachment", Guid.Empty);

        // Set default template ID
        node.SetDefaultPageTemplateID(DataClass.ClassDefaultPageTemplateID);

        // Ensures documents consistency (blog post hierarchy etc.)
        DocumentManager.EnsureDocumentsConsistency();

        // Insert the document
        DocumentHelper.InsertDocument(node, DocumentManager.ParentNodeID, DocumentManager.Tree);

        // Add the file
        DocumentHelper.AddAttachment(node, "FileAttachment", FileUpload.PostedFile, DocumentManager.Tree, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize);
    }
    protected void ProcessDirectUploader()
    {
        TreeNode node = DocumentManager.Node;

        // Create new document
        string fileName = Path.GetFileNameWithoutExtension(ucDirectUploader.AttachmentName);

        int maxFileNameLength = FileNameFieldInfo.Size;

        if (fileName.Length > maxFileNameLength)
        {
            fileName = fileName.Substring(0, maxFileNameLength);
        }

        node.DocumentName = fileName;
        if (node.ContainsColumn("FileDescription"))
        {
            node.SetValue("FileDescription", txtFileDescription.Text);
        }
        node.SetValue("FileAttachment", Guid.Empty);

        // Set default template ID
        node.SetDefaultPageTemplateID(DataClass.ClassDefaultPageTemplateID);

        // Ensures documents consistency (blog post hierarchy etc.)
        DocumentManager.EnsureDocumentsConsistency();

        // Insert the document
        DocumentHelper.InsertDocument(node, DocumentManager.ParentNodeID, DocumentManager.Tree);

        // Set the attachment GUID later - important when document is under workflow and  using check-in/check-out
        node.SetValue("FileAttachment", ucDirectUploader.Value);
    }
示例#3
0
    private void btnOk_Click(object sender, EventArgs e)
    {
        // Validate all required data for new blog
        string errorMessage = ValidateData();

        if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert))
        {
            errorMessage = GetString("cmsdesk.bloglicenselimits");
        }

        // Get current user
        CurrentUserInfo user = CMSContext.CurrentUser;

        if (errorMessage == "")
        {
            // Get parent node for new blog
            TreeProvider tree   = new TreeProvider(user);
            TreeNode     parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, BlogParentPath.TrimEnd('%'), TreeProvider.ALL_CULTURES);
            if (parent != null)
            {
                if (!CheckPermissions || user.IsAuthorizedToCreateNewDocument(parent, "cms.blog"))
                {
                    bool     useParentNodeGroupID = tree.UseParentNodeGroupID;
                    TreeNode blogNode             = null;
                    try
                    {
                        // Reflect group document
                        tree.UseParentNodeGroupID = true;

                        // Initialize and create new blog node
                        blogNode = TreeNode.New("cms.blog", tree);
                        blogNode.SetValue("BlogName", txtName.Text.Trim());
                        blogNode.SetValue("BlogDescription", txtDescription.Text.Trim());
                        blogNode.SetValue("BlogAllowAnonymousComments", BlogAllowAnonymousComments);
                        blogNode.SetValue("BlogModerateComments", BlogModerateComments);
                        blogNode.SetValue("BlogOpenCommentsFor", BlogOpenCommentsFor);
                        blogNode.SetValue("BlogSendCommentsToEmail", BlogSendCommentsToEmail);
                        blogNode.SetValue("BlogSideColumnText", BlogSideColumnText);
                        blogNode.SetValue("BlogUseCAPTCHAForComments", BlogUseCAPTCHAForComments);
                        blogNode.SetValue("BlogModerators", BlogModerators);
                        if (BlogTeaser == Guid.Empty)
                        {
                            blogNode.SetValue("BlogTeaser", null);
                        }
                        else
                        {
                            blogNode.SetValue("BlogTeaser", BlogTeaser);
                        }

                        blogNode.SetValue("NodeOwner", user.UserID);

                        if (NewBlogTemplate != null)
                        {
                            // Get the BlogMonth class to set the default page template
                            if (NewBlogTemplate == "")
                            {
                                DataClassInfo blogClass = DataClassInfoProvider.GetDataClass("CMS.Blog");
                                if (blogClass != null)
                                {
                                    blogNode.SetDefaultPageTemplateID(blogClass.ClassDefaultPageTemplateID);
                                }
                            }
                            else
                            {
                                // Set the selected template
                                PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(NewBlogTemplate);
                                if (pti != null)
                                {
                                    blogNode.NodeTemplateForAllCultures = true;
                                    blogNode.NodeTemplateID             = pti.PageTemplateId;
                                }
                            }
                        }

                        // Trackbacks are denied by default
                        blogNode.SetValue("BlogEnableTrackbacks", false);

                        blogNode.DocumentName    = txtName.Text.Trim();
                        blogNode.DocumentCulture = CMSContext.CurrentUser.PreferredCultureCode;
                        DocumentHelper.InsertDocument(blogNode, parent, tree);
                    }
                    finally
                    {
                        tree.UseParentNodeGroupID = useParentNodeGroupID;
                    }

                    if (RedirectToNewBlog)
                    {
                        // Redirect to the new blog
                        URLHelper.Redirect(CMSContext.GetUrl(blogNode.NodeAliasPath));
                    }
                    else
                    {
                        // Display info message
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("General.ChangesSaved");
                    }
                }
                else
                {
                    // Not authorized to create blog
                    errorMessage = GetString("blogs.notallowedtocreate");
                }
            }
            else
            {
                // Parent node was not found
                errorMessage = GetString("Blogs.NewBlog.PathNotFound");
            }
        }

        if (errorMessage != "")
        {
            // Display error message
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }