示例#1
0
        protected void GenerateButton_Click(object sender, EventArgs e)
        {
            // save the configured options
            SiteMapOptions options = new SiteMapOptions();

            options.Load(new CommonSiteMapOptionKeys());
            string sitemapPath = SitemapPath.Text;

            if (!string.IsNullOrEmpty(sitemapPath))
            {
                string newPath = Path.Combine(Request.MapPath("~/"), sitemapPath);
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                options.SiteMapDataPath = newPath;
            }
            else
            {
                options.SiteMapDataPath = Request.MapPath("~/");
            }
            options.SiteMapFileName           = "SiteMap.xml";
            options.OverwriteSiteMapFile      = true;
            options.IncludeCategories         = IndexItems.Items[0].Selected;
            options.IncludeProducts           = IndexItems.Items[1].Selected;
            options.IncludeWebpages           = IndexItems.Items[2].Selected;
            options.CompressedSiteMapFileName = "SiteMap.xml.gz";
            options.OverwriteCompressedFile   = true;
            options.DefaultUrlPriority        = 0.5M;
            options.DefaultChangeFrequency    = (changefreq)Enum.Parse(typeof(changefreq), ChangeFrequency.SelectedValue);
            options.Save(new CommonSiteMapOptionKeys());

            // generate the map
            List <string>         messages = new List <string>();
            CommonSiteMapProvider provider = new CommonSiteMapProvider();
            bool success;

            if (UseCompression.Checked)
            {
                success = provider.CreateAndCompressSiteMap(options, ref messages);
            }
            else
            {
                success = provider.CreateSiteMap(options, ref messages);
            }

            // report the outcome
            if (success)
            {
                SuccessMessage.Visible = true;
                SuccessMessage.Text    = GetMessageLiteral(messages);
            }
            else
            {
                FailureMessage.Visible = true;
                FailureMessage.Text    = GetMessageLiteral(messages);
            }
        }