コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string aliasPath   = QueryHelper.GetString("aliaspath", "");
        string webpartId   = QueryHelper.GetString("webpartid", "");
        string zoneId      = QueryHelper.GetString("zoneid", "");
        Guid   webpartGuid = QueryHelper.GetGuid("webpartguid", Guid.Empty);
        int    templateId  = QueryHelper.GetInteger("templateId", 0);

        PageTemplateInfo pti = null;

        if (templateId > 0)
        {
            pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);
        }

        if (pti != null)
        {
            // Get web part
            WebPartInstance webPart = pti.TemplateInstance.GetWebPart(webpartGuid, webpartId);
            if (webPart != null)
            {
                StringBuilder sb         = new StringBuilder();
                Hashtable     properties = webPart.Properties;

                // Get the webpart object
                WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                if (wi != null)
                {
                    // Add the header
                    sb.Append("Webpart properties (" + wi.WebPartDisplayName + ")" + Environment.NewLine + Environment.NewLine);
                    sb.Append("Alias path: " + aliasPath + Environment.NewLine);
                    sb.Append("Zone ID: " + zoneId + Environment.NewLine + Environment.NewLine);


                    string wpProperties = "<default></default>";
                    // Get the form info object and load it with the data

                    if (wi.WebPartParentID > 0)
                    {
                        // Load parent properties
                        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID);
                        if (wpi != null)
                        {
                            wpProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WebPartProperties);
                        }
                    }
                    else
                    {
                        wpProperties = wi.WebPartProperties;
                    }

                    FormInfo fi = new FormInfo(wpProperties);

                    // General properties of webparts
                    string beforeFormDefinition = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wi.WebPartType, PropertiesPosition.Before);
                    string afterFormDefinition  = PortalFormHelper.GetWebPartProperties((WebPartTypeEnum)wi.WebPartType, PropertiesPosition.After);

                    // General properties before custom
                    if (!String.IsNullOrEmpty(beforeFormDefinition))
                    {
                        // Load before definition
                        fi = new FormInfo(FormHelper.MergeFormDefinitions(beforeFormDefinition, wpProperties, true));

                        // Add Default category for first before items
                        sb.Append(Environment.NewLine + "Default" + Environment.NewLine + Environment.NewLine + Environment.NewLine);
                    }


                    // General properties after custom
                    if (!String.IsNullOrEmpty(afterFormDefinition))
                    {
                        // Load after definition
                        fi = new FormInfo(FormHelper.MergeFormDefinitions(fi.GetXmlDefinition(), afterFormDefinition, true));
                    }

                    // Generate all properties
                    sb.Append(GetProperties(fi.GetFormElements(true, false), webPart));

                    // Send the text file to the user to download
                    UTF8Encoding enc  = new UTF8Encoding();
                    byte[]       file = enc.GetBytes(sb.ToString());

                    HTTPHelper.AddContentDispositionHeader(Response, true, $"webpartproperties_{webPart.ControlID}.txt");
                    Response.ContentType = "text/plain";
                    Response.BinaryWrite(file);

                    RequestHelper.EndResponse();
                }
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Builds the export file and writes it to the response.
    /// </summary>
    /// <param name="category">Settings category</param>
    /// <param name="searchText">Text to search for</param>
    /// <param name="searchInDescription">True, if key description should be included in the search</param>
    /// <param name="site">Site</param>
    private void Export(SettingsCategoryInfo category, string searchText, bool searchInDescription, SiteInfo site = null)
    {
        var isSearch = !string.IsNullOrEmpty(searchText);

        var isSite   = (site != null);
        var siteName = isSite ? site.SiteName : null;

        var sb = new StringBuilder();

        // Append file title
        if (isSite)
        {
            sb.Append("Settings for site \"", site.DisplayName, "\"");
        }
        else
        {
            sb.Append("Global settings");
        }
        sb.Append(", ");
        if (isSearch)
        {
            sb.Append("search text \"", searchText, "\"");
        }
        else
        {
            string categoryNames = ResHelper.LocalizeString(FormatCategoryPathNames(category.CategoryIDPath));
            sb.Append("category \"", categoryNames, "\"");
        }
        sb.AppendLine();
        sb.AppendLine();

        // Get groups
        var groups = GetGroups(category, isSearch);

        // Append groups and keys
        foreach (var group in groups)
        {
            // Get keys
            var keys = GetKeys(group, isSite, searchText, searchInDescription).ToArray();
            if (!keys.Any())
            {
                // Skip empty groups
                continue;
            }

            // Get formatted keys
            string keysFormatted = FormatKeys(keys, siteName);
            if (string.IsNullOrEmpty(keysFormatted))
            {
                // Skip empty groups
                continue;
            }

            // Append group title
            sb.AppendLine();
            if (isSearch)
            {
                string categoryNames = ResHelper.LocalizeString(FormatCategoryPathNames(group.CategoryIDPath));
                sb.Append(categoryNames);
            }
            else
            {
                string groupDisplayNameLocalized = ResHelper.LocalizeString(group.CategoryDisplayName);
                sb.Append(groupDisplayNameLocalized);
            }
            sb.AppendLine();
            sb.Append("--------------------------------------------------");
            sb.AppendLine();
            sb.AppendLine();

            // Append group keys
            sb.Append(keysFormatted);
        }

        // Write to response
        var fileName = string.Format("{0}_{1}.txt", (site == null ? "Global" : site.DisplayName), ValidationHelper.GetIdentifier(category.CategoryName, "_"));

        HTTPHelper.AddContentDispositionHeader(Response, true, fileName);
        Response.ContentType = "text/plain";
        Response.Write(sb.ToString());
        RequestHelper.EndResponse();
    }