DNN - Adding a secure folder - module

I'm currently coding a module where users can add secure folders.
But the instance method requires a parameter of an instance name, i've no idea what they mean. Could someone explain it to me?
DotNetNuke.Services.FileSystem.SecureFolderProvider.Instance("Test2").AddFolder(txtFolderName.Text, new FolderMappingInfo
{
PortalID = base.PortalId,
MappingName = txtFolderName.Text
});
Any suggestions what i am doing wrong?

With some help of garethbh, i came up with this:
// Get folder mapping
var folderMapping = FolderMappingController.Instance.GetFolderMapping(PortalId, "Secure");
// Add folder and get the result back of the folder information
var folder = FolderManager.Instance.AddFolder(new FolderMappingInfo
{
FolderProviderType = folderMapping.FolderProviderType,
FolderMappingID = 9,
Priority = 2,
PortalID = PortalId,
}, portalFilePath);
This works fine for me.

You need to pass in the name of your folder mapping provider type. If you search for usages of SecureFolderProvider's base class (FolderProvider), you'll see what you need.
Eg:
var folderMapping = FolderMappingController.Instance.GetFolderMapping(PortalId, "Secure");
if (folderMapping != null)
{
SecureFolderProvider.Instance(folderMapping.FolderProviderType).AddFolder(folderPath, folderMapping);
}
I've never actually used the secure folder provider before so I'm just guessing you need the one with the 'Secure' mapping name (but you may want to use 'Database' depending on your needs or create your own folder provider). See the FolderMappings table in the database for available types.
From the DNN wiki http://www.dnnsoftware.com/wiki/Page/Folder-Types and http://www.dnnsoftware.com/wiki/Page/Folder-providers

Related

How to add an User Content through Sensenet Client?

I want to add an User Content of Sensenet from a client which developed by .NET.
Please give me a solution.
Thanks so much.
You should be able to create users the same way as any other content, by providing the parent, the content type name and a few mandatory fields.
The example below assumes that you already initialized the client, you have the /Root/IMS/MyDomain/MyOrgUnit in your repo and there is no existing user there with the same name.
var user = Content.CreateNew("/Root/IMS/MyDomain/MyOrgUnit", "User", "johnsmith");
user["LoginName"] = "johnsmith"; // best practice: same as the content name in the line above
user["Password"] = "123456789";
user["FullName"] = "John Smith";
user["Email"] = "johnsmith#example.com"; // this has to be unique under the domain
user["Enabled"] = true; // to let the user actually log in
await user.SaveAsync();
Let us know if you encounter any errors.

get the sys_file_metadata values using typo3 repository methods

I am building an extension using typo3. I got stuck at one point. That is, I need the sys_file_metadata value along with sys_file informations. I am getting sys_file informations using repository methods. But not getting the metadata informations like title, description.
Can anyone help me to find a repository method to fetch metadata informations using repository methods?
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); // create instance to storage repository
$storage = $storageRepository->findByUid(2); // get file storage with uid 1 (this should by default point to your fileadmin/ directory)
$folder = $storage->getFolder('/Audios/',false);
$files = $storage->getFilesInFolder($folder);
foreach ($files as $key => $value) {
$array_file = $files[$key]->toArray();
$uid = $array_file['uid'];
$array['name'] = $array_file['name'];
$array['extension'] = $array_file['extension'];
}
I found the answer. We can use the method
$value->_getMetaData();
To get the specified properties, we can use
$value->getProperty('description');

Sitecore Glass mapper GetItem<TypeName>(guid) always return null

I saw a related question:
Sitecore Glass Mapper always null
But unfortunately it does not give a solution for my case.
Here goes a code snippet:
var db = Factory.GetDatabase("master");
var context = new SitecoreContext();
// the ID of Needed item
var g = new Guid("{F21C04FE-8826-41AB-9F3C-F7BDF5B35C76}");
// just to test if it's possible to fetch item using db.GetItem
var i = db.GetItem(new ID(g), Language.Current, Sitecore.Data.Version.Latest);
// Grab item
var t = context.GetItem<Article>(g);
In the code above:
i is not null
t is null
Article is the simple class like:
[SitecoreType(TemplateId = "{4C4EC1DA-EB77-4001-A7F9-E4C2F61A9BE9}")]
public class Article
{
[SitecoreField(FieldName = "Title")]
public string Title { get; set; }
}
There are only one language installed in Sitecore - en, it has been specified in the web.config in the items as well.
Also I have added GlassMapperSc.Start(); to Application_Start in the Global.asax.cs and added my assembly to the list of included assemblies via var attributes = new AttributeConfigurationLoader(new[] { "Assembly.Name" }); and I succeeded to find my class in the SitecoreContext mappings.
It does not looks like a language issue, as stated in the link provided in the very beginning. And I'm struggling with it already for a pretty long time, but no luck...
Thank You!
I just noticed that you are using master db for the Sitecore DB and SitecoreContext for Glass.
The SitecoreContext class will use the database that is defined by the Sitecore.Context.Database property at runtime. This probably means that it is using the web database.
Can you check that you have published the item to the web database or instead using:
var context = new SitecoreService("master");

dynamic file path in log4php

I am new to log4php.
I would like to save the log files in the format /logs/UserId/Info_ddmmyyyy.php
where the UserId is dynamic data.
(I would basically like to save one log per user.)
Is there any way to change the log file path dynamically?
This behaviour is not supported by default. But you can extend LoggerAppenderFile (or RollingFile, DailyFile whatever your preference is) to support it.
Create your own class for that and make it load to your script.
Then extend from this class:
http://svn.apache.org/repos/asf/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
class MyAppender extends LoggerAppenderFile { ... }
You'll need to overwrite the setFile() method, similar to:
public function setFile($file) {
$path = getYourFullPath();
$this->file = $path.$file;
}
After all you need to use your new Appender in you config
log4php.appender.myAppender = MyAppender
log4php.appender.myAppender.layout = LoggerLayoutSimple
log4php.appender.myAppender.file = my.log
Please note, instead of giving your full path to the log file you now need to add a plain name. The full path (including username) must be calculated with your getYourFullPath() method.
Hope that helps!
Christian

ASP.NET Site Maps

Does anyone have experience creating SQL-based ASP.NET site-map providers?
I have the default XML file web.sitemap working properly with my Menu and SiteMapPath controls, but I'll need a way for the users of my site to create and modify pages dynamically.
I need to tie page viewing permissions into the standard ASP.NET membership system as well.
The Jeff Prosise version from MSDN magazine works pretty well, but it has a few flaws:
AddNode freaks out with links to external sites on your menu (www.google.com, etc.)
Here's my fix in BuildSiteMap():
SiteMapNode node = GetSiteMapNodeFromReader(reader);
string url = node.Url;
if (url.Contains(":"))
{
string garbage = Guid.NewGuid().ToString(); // SiteMapNode needs unique URLs
node.Url = "~/dummy_" + garbage + ".aspx";
AddNode(node, _root);
node.Url = url;
}
else
{
AddNode(node, _root);
}
SQLDependency caching is cool, but if you don't want to make a trip to the DB everytime your menu loads (to check to see if the dependency has changed) and your menus don't change very often, then why not use HttpRuntime.Cache instead?
public override SiteMapNode RootNode
{
get
{
SiteMapNode temp = (SiteMapNode)HttpRuntime.Cache["SomeKeyName"];
if (temp == null)
{
temp = BuildSiteMap();
HttpRuntime.Cache.Insert("SomeKeyName", temp, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration);
}
return temp;
}
}