Extensions and there XML files.

Topics: ASP.NET 2.0
Sep 3, 2009 at 4:56 PM

Hi there!

I am working on an extension in BE.NET, and wonder if it’s possible to override the place where the XML file is saved. This code produce a XML file in App_Data/datastore/extensions.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls; 

/// <summary>
/// Summary description for RandomImageEditor
/// </summary>

 

[Extension("The header picture will be added a short description.", "1.0", "<a href=\"http://blog.knigge.dk\">blog.knigge.dk</a>")]
public class RandomImageEditor
{
    static protected ExtensionSettings _settings = null;
    public RandomImageEditor()
           {
        ExtensionSettings settings = new ExtensionSettings("RandomImageEditor");
        settings.AddParameter("Image1", "Image #1", 50, true);
        settings.AddParameter("Description1", "Description #1", 50, true);
         .
         .
        settings.AddParameter("Image10", "Image #10", 50, true);
        settings.AddParameter("Description10", "Description #10", 50, true);
        settings.IsScalar = true; 

        // describe specific rules for entering parameters
        settings.Help = "The header picture will be added a short description.<br/><br/>URL path to image folder (i.e. ~/themes/black/headerphoto/)<br/>Labels that are empty should be set to none (i.e. none)<br/><br/>RandomImage was originally created by <a href=\"http://tumelty.com\">Paul Tumelty</a>.";

        //------------------------------------------------------
        ExtensionManager.ImportSettings(settings);
        _settings = ExtensionManager.GetSettings("RandomImageEditor");      
           }
}

 

Any help will be appreciated!

Thanks in advance

Poul

Coordinator
Sep 4, 2009 at 7:07 PM

Check out BusinessLogic/Providers/XmlProvider/DataStore.cs, you only need to change these 3 strings to point to any writable folder.

private string StorageLocation(ExtensionType exType)
{
switch (exType)
{
case ExtensionType.Extension:
return HostingEnvironment.MapPath(Path.Combine(BlogSettings.Instance.StorageLocation, @"datastore\extensions\"));
case ExtensionType.Widget:
return HostingEnvironment.MapPath(Path.Combine(BlogSettings.Instance.StorageLocation, @"datastore\widgets\"));
case ExtensionType.Theme:
return HostingEnvironment.MapPath(Path.Combine(BlogSettings.Instance.StorageLocation, @"datastore\themes\"));
}
return string.Empty;
}

You can also plug in your own XML provider so you don't have to break compatibility with core project (more involved).
I probably will change this to be a setting just as StorageLocation.
Sep 4, 2009 at 10:56 PM

Hi Rtur!

Many thanks for your answer. As you say I don’t want to break compatibility with the core Project. All I want is to extract information from RandomImageEditor.xml (and only that file) during a page load in site.master.cs, but that’s not allowed. I have also tried to extract the information from
_settings.parameters as you can see (it’s there), but I can’t address it. Is it not allowed?

 image is missing - will ship to you directly, hope it's OK!

I’m not a hard core programmer, but I’m trying, so help is appreciated.

Thanks again

Poul  

Coordinator
Sep 5, 2009 at 5:48 PM

Hi Poul, not sure I understood what you trying to accomplish. Are you having trouble retrieving values saved into settings object? If so, you can get hold on it in your case with something like this:

string img1 = _settings.GetSingleValue("Image1");

Sep 5, 2009 at 9:35 PM

Hi again Rtur!

Fine guess! You hit the target! I’m on the road again. Many thanks!

Poul