After I got tired to talk to our users that they should upload only web friendly named files and they don't care about it (or they don't understand it or perhaps they have something like Alzheimer) I added character replacing to the upload field of umbraco.
First I added a new section to the umbraco.config under content:
<content>
<filenameReplacing>
<char org=" ">-</char>
<char org="""></char>
<char org=";"></char>
<char org="/"></char>
<char org=":"></char>
<char org="+">plus</char>
<char org="*">star</char>
<char org="&"></char>
<char org="?"></char>
</filenameReplacing>
</content>
After that I added a new property to the UmbracoSettings class in the umbraco.businesslogic project:
/// <summary>
/// Gets a list of characters that will be replaced when uploadingFiles via fileUpload
/// </summary>
/// <value>The filename replacement characters for uploaded Files.</value>
public static XmlNode FilenameReplaceCharacters
{
get { return GetKeyAsNode("/settings/content/filenameReplacing"); }
}
Finally I added some lines to uploadField class in the umbraco.editorControls project
if (umbraco.UmbracoSettings.UploadAllowDirectories)
{
// Changed by TH to replace filename characters (2009-05-26)
filename = this.getFilename(_text.Substring(_text.LastIndexOf("\\") + 1, _text.Length - _text.LastIndexOf("\\") - 1).ToLower());
// Create a new folder in the /media folder with the name /media/propertyid
System.IO.Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(umbraco.GlobalSettings.Path + "/../media/" + _data.PropertyId.ToString()));
_fullFilePath = System.Web.HttpContext.Current.Server.MapPath(umbraco.GlobalSettings.Path + "/../media/" + _data.PropertyId + "/" + filename);
this.PostedFile.SaveAs(_fullFilePath);
_data.Value = "/media/" + _data.PropertyId + "/" + filename;
}
else
{
// Changed by TH to replace filename characters (2009-05-26)
filename = this.getFilename(System.IO.Path.GetFileName(this.PostedFile.FileName));
filename = _data.PropertyId + "-" + filename;
_fullFilePath = System.Web.HttpContext.Current.Server.MapPath(umbraco.GlobalSettings.Path + "/../media/" + filename);
this.PostedFile.SaveAs(_fullFilePath);
_data.Value = "/media/" + filename;
}
and a new function:
/// <summary>
/// Function to get the filename with replaced characters
/// </summary>
/// <param name="originalFilename"></param>
/// <returns></returns>
private string getFilename(string originalFilename)
{
string retVal = System.IO.Path.GetFileNameWithoutExtension(originalFilename);
System.Xml.XmlNode replaceChars = UmbracoSettings.FilenameReplaceCharacters;
foreach (System.Xml.XmlNode n in replaceChars.SelectNodes("char"))
if (n.Attributes.GetNamedItem("org") != null && n.Attributes.GetNamedItem("org").Value != "")
retVal = retVal.Replace(n.Attributes.GetNamedItem("org").Value, xmlHelper.GetNodeValue(n));
return retVal + System.IO.Path.GetExtension(originalFilename);
}
I recompiled the solution and replaced the businesslogic.dll, the umbraco.editorControls.dll and the umbracoSettings.config on the webserver.
This works fine for me and saves me a lot of time talking to the users uploading web friendly filenames.
Your feedback is welcome
After a long time offline I have published now a new package called BlogCumulus v1.0. The BlogCumulus is a component originally created by Roy Tanck for Wordpress. The BlogCumulus is a flash driven TagCloud. BlogCumulus.Net is the .Net component of BlogCumulus written by Ryan Tomlinson. I took his code and made a .Net UserControls for Umbraco using the build in Tags.
On the first step I walked through the code and mentioned that the umbraco.editorControls.Tags.library provides a function returning the Tags as objects. Unfortunately this implementation didn't load the number of usages of the Tags, so that I had switch to my own tag retrieving. But stop. In the code of the library the SQL returns the numbers of nodes. Only the ITag interface and the Tag class doesn't provide a Count Property. So I took the umbraco v.4.0.1 Code added the Count Property to the ITag interface
public interface ITag
{
int Id { get; }
string TagCaption { get; }
string Group { get; }
int Count { get; }
}
added the needed changes to the Tag class in umbrac.editorControls.tags.library.cs
public Tag(int id, string tag, string group, int count)
{
Id = id;
TagCaption = tag;
Group = group;
Count = count;
}
public int Count { get; set; }
and one line to the function convertSqlToTags in the umbraco.editorControls.tags.library
private static List<umbraco.interfaces.ITag> convertSqlToTags(string sql, IParameter param)
{
List<umbraco.interfaces.ITag> tags = new List<umbraco.interfaces.ITag>();
IRecordsReader rr = SqlHelper.ExecuteReader(sql, param);
while (rr.Read())
{
tags.Add(new Tag(
rr.GetInt("id"),
rr.GetString("tag"),
rr.GetString("group"),
rr.GetInt("nodeCount")));
}
rr.Close();
return tags;
}
I recompiled these two dlls and referenced it in my new project. I added an issue to codeplex and also a small patch. Vote for it and it will hopefully integrated in v4.0.2, so that we use this package without hacks.
The package now includes one dll
(thoehler.com.blogcumulus.dll), one UserControl (BlogCumulus.ascx)
and one Macro (th.BlogCumulus). On the macro you can set several
parameters: The speed of the rotation in %, the width and the
height of the control, the font color (in hex notation) the
link-template ({0} will be replaced with the tag name) and the
paths to the js and the swf. You also have set the TagGroup with
for which this TagCould should be set.
First of all this package needs the two recompiled dlls from umbraco. I also made this with .NET 3.5 using LINQ, so it needs .NET 3.5. If there are many Users who wants to have this in .NET 2.0 I can do it or you can do it by requesting the project.
I hope you will enjoy this package and please feel free to give me your feedback.
02.04.12 11:50: wpi feed wurde noch nicht aktualisiert
02.04.12 10:31: Yihaa, ich sehe Schnee
02.04.12 09:52: @Kilroy576 winke winke zurück und danke
02.03.12 20:51: +1 RT @attack_monkey: @umbraco stalker.Umbraco.com
02.03.12 20:51: Das passiert wenn man Kinder mal unbeaufsichtigt lässt: http://t.co/p2HrAPm0 #monster
![]()
This blog is written by Thomas Höhler. Living next to Frankfurt, Germany,
I am trying to share my experiences about
Umbraco [the most flexible CMS I know],
my ClientTools for Umbraco,
and some other more or less usefull stuff