diff --git a/lib/businesslogic.dll b/lib/businesslogic.dll
index 0570746..0f9ca79 100644
Binary files a/lib/businesslogic.dll and b/lib/businesslogic.dll differ
diff --git a/lib/cms.dll b/lib/cms.dll
index 06b8359..ea6ca79 100644
Binary files a/lib/cms.dll and b/lib/cms.dll differ
diff --git a/lib/interfaces.dll b/lib/interfaces.dll
index f80d359..ab0ca30 100644
Binary files a/lib/interfaces.dll and b/lib/interfaces.dll differ
diff --git a/lib/umbraco.DataLayer.dll b/lib/umbraco.DataLayer.dll
index 8a069a1..b989ac2 100644
Binary files a/lib/umbraco.DataLayer.dll and b/lib/umbraco.DataLayer.dll differ
diff --git a/lib/umbraco.dll b/lib/umbraco.dll
index c577d7f..53e9dd8 100644
Binary files a/lib/umbraco.dll and b/lib/umbraco.dll differ
diff --git a/lib/umbraco.editorControls.dll b/lib/umbraco.editorControls.dll
index 4f03f81..9c9b9a2 100644
Binary files a/lib/umbraco.editorControls.dll and b/lib/umbraco.editorControls.dll differ
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultFileMediaFactory.cs b/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultFileMediaFactory.cs
index 823195e..3304bae 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultFileMediaFactory.cs
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultFileMediaFactory.cs
@@ -16,24 +16,25 @@ public class DefaultFileMediaFactory : MediaFactory
#region IMediaFactory Members
- public override Media CreateMedia(IconI parent, HttpPostedFile uploadFile)
- {
- string filename = uploadFile.FileName;
+ public override Media CreateMedia(IconI parent, HttpPostedFile uploadFile)
+ {
+ //Get the safe file name
+ string filename = SafeFileName(uploadFile.FileName);
- // Create new media object
- Media media = Media.MakeNew(filename, MediaType.GetByAlias("File"),
- new User(0), parent.Id);
+ // Create new media object
+ Media media = Media.MakeNew(filename, MediaType.GetByAlias("File"),
+ new User(0), parent.Id);
- // Get umbracoFile property
- int propertyId = media.getProperty("umbracoFile").Id;
+ // Get umbracoFile property
+ int propertyId = media.getProperty("umbracoFile").Id;
- // Set media properties
- media.getProperty("umbracoFile").Value = VirtualPathUtility.Combine(ConstructRelativeDestPath(propertyId), filename);
- media.getProperty("umbracoBytes").Value = uploadFile.ContentLength;
- media.getProperty("umbracoExtension").Value = VirtualPathUtility.GetExtension(filename).Substring(1);
+ // Set media properties
+ media.getProperty("umbracoFile").Value = VirtualPathUtility.Combine(ConstructRelativeDestPath(propertyId), filename);
+ media.getProperty("umbracoBytes").Value = uploadFile.ContentLength;
+ media.getProperty("umbracoExtension").Value = VirtualPathUtility.GetExtension(filename).Substring(1);
- return media;
- }
+ return media;
+ }
#endregion
}
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultImageMediaFactory.cs b/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultImageMediaFactory.cs
index 88fbe2a..43c60ea 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultImageMediaFactory.cs
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/DefaultImageMediaFactory.cs
@@ -28,46 +28,47 @@ public class DefaultImageMediaFactory : MediaFactory
#region IMediaFactory Members
- public override Media CreateMedia(IconI parent, HttpPostedFile uploadFile)
- {
- string filename = uploadFile.FileName;
+ public override Media CreateMedia(IconI parent, HttpPostedFile uploadFile)
+ {
+ //Get the safe file name
+ string filename = SafeFileName(uploadFile.FileName);
- // Create new media object
- Media media = Media.MakeNew(filename, MediaType.GetByAlias("Image"),
- new User(0), parent.Id);
+ // Create new media object
+ Media media = Media.MakeNew(filename, MediaType.GetByAlias("Image"),
+ new User(0), parent.Id);
- // Get Image object, width and height
- Image image = Image.FromStream(uploadFile.InputStream);
- int fileWidth = image.Width;
- int fileHeight = image.Height;
+ // Get Image object, width and height
+ Image image = Image.FromStream(uploadFile.InputStream);
+ int fileWidth = image.Width;
+ int fileHeight = image.Height;
- // Get umbracoFile property
- int propertyId = media.getProperty("umbracoFile").Id;
+ // Get umbracoFile property
+ int propertyId = media.getProperty("umbracoFile").Id;
- // Get paths
- string relativeDestPath = ConstructRelativeDestPath(propertyId);
- string relativeDestFilePath = VirtualPathUtility.Combine(relativeDestPath, filename);
- string ext = VirtualPathUtility.GetExtension(filename).Substring(1);
+ // Get paths
+ string relativeDestPath = ConstructRelativeDestPath(propertyId);
+ string relativeDestFilePath = VirtualPathUtility.Combine(relativeDestPath, filename);
+ string ext = VirtualPathUtility.GetExtension(filename).Substring(1);
- // Set media properties
- SetImageMediaProperties(media, relativeDestFilePath, fileWidth, fileHeight, uploadFile.ContentLength, ext);
+ // Set media properties
+ SetImageMediaProperties(media, relativeDestFilePath, fileWidth, fileHeight, uploadFile.ContentLength, ext);
- // Create directory
- if (UmbracoSettings.UploadAllowDirectories)
- Directory.CreateDirectory(HttpContext.Current.Server.MapPath(relativeDestPath));
+ // Create directory
+ if (UmbracoSettings.UploadAllowDirectories)
+ Directory.CreateDirectory(HttpContext.Current.Server.MapPath(relativeDestPath));
- // Generate thumbnail
- string absoluteDestPath = HttpContext.Current.Server.MapPath(relativeDestPath);
- string absoluteDestFilePath = Path.Combine(absoluteDestPath, Path.GetFileNameWithoutExtension(filename) + "_thumb");
- GenerateThumbnail(image, 100, fileWidth, fileHeight, absoluteDestFilePath + ".jpg");
+ // Generate thumbnail
+ string absoluteDestPath = HttpContext.Current.Server.MapPath(relativeDestPath);
+ string absoluteDestFilePath = Path.Combine(absoluteDestPath, Path.GetFileNameWithoutExtension(filename) + "_thumb");
+ GenerateThumbnail(image, 100, fileWidth, fileHeight, absoluteDestFilePath + ".jpg");
- // Generate additional thumbnails based on PreValues set in DataTypeDefinition uploadField
- GenerateAdditionalThumbnails(image, fileWidth, fileHeight, absoluteDestFilePath);
+ // Generate additional thumbnails based on PreValues set in DataTypeDefinition uploadField
+ GenerateAdditionalThumbnails(image, fileWidth, fileHeight, absoluteDestFilePath);
- image.Dispose();
+ image.Dispose();
- return media;
- }
+ return media;
+ }
// -------------------------------------------------------------------------
// Private members
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/IMediaFactory.cs b/src/noerd.Umb.DataTypes.multipleFileUpload/IMediaFactory.cs
index acfe2af..ad88293 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/IMediaFactory.cs
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/IMediaFactory.cs
@@ -28,5 +28,12 @@ public interface IMediaFactory
/// The umbracoFile property id
/// The path to the folder where the uploaded file will be placed.
string ConstructRelativeDestPath(int propertyId);
+
+ ///
+ /// Function for handling illegal characters in the file name.
+ ///
+ /// The uploaded file name.
+ /// The safe file name that the uploaded file will be saved with.
+ string SafeFileName(string fileName);
}
}
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/MediaFactory.cs b/src/noerd.Umb.DataTypes.multipleFileUpload/MediaFactory.cs
index d6609a1..6e9a707 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/MediaFactory.cs
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/MediaFactory.cs
@@ -2,6 +2,8 @@
using umbraco.cms.businesslogic.media;
using umbraco.BusinessLogic.console;
using System.Web;
+using System;
+using System.Text.RegularExpressions;
namespace noerd.Umb.DataTypes.multipleFileUpload
{
@@ -37,5 +39,13 @@ public string ConstructRelativeDestPath(int propertyId)
return VirtualPathUtility.ToAbsolute(MEDIA_PATH);
}
+
+ public string SafeFileName(string fileName)
+ {
+ if (!String.IsNullOrEmpty(fileName))
+ return Regex.Replace(fileName, @"[^a-zA-Z0-9\-\.\/\:]{1}", "_");
+ else
+ return String.Empty;
+ }
}
}
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/MultipleFileUpload.cs b/src/noerd.Umb.DataTypes.multipleFileUpload/MultipleFileUpload.cs
index 73c017e..8e2d87a 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/MultipleFileUpload.cs
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/MultipleFileUpload.cs
@@ -149,49 +149,53 @@ private static void ConfigValidationEventHandler(object sender, ValidationEventA
// Public members
// -------------------------------------------------------------------------
- public static void HandleUpload(HttpContext context, int nodeId)
- {
- context.Response.Write(context.Request.Files.Count);
-
- // loop through uploaded files
- for (int j = 0; j < context.Request.Files.Count; j++)
- {
- // get parent node
- Media parentNode = new Media(nodeId);
-
- // get the current file
- HttpPostedFile uploadFile = context.Request.Files[j];
-
- // if there was a file uploded
- if (uploadFile.ContentLength > 0)
- {
- // Get concrete MediaFactory
- IMediaFactory factory = GetMediaFactory(uploadFile);
- // Create media Item
- Media media = factory.CreateMedia(parentNode, uploadFile);
-
- // Get path
- int propertyId = media.getProperty("umbracoFile").Id;
- string path = HttpContext.Current.Server.MapPath(factory.ConstructRelativeDestPath(propertyId));
-
- // Create directory
- if (UmbracoSettings.UploadAllowDirectories)
- Directory.CreateDirectory(path);
-
- // Save file
- string filePath = Path.Combine(path, uploadFile.FileName);
- uploadFile.SaveAs(filePath);
-
- // Close stream
- uploadFile.InputStream.Close();
-
- // Save media
- media.Save();
- // Genereate xml cache
- media.XmlGenerate(new XmlDocument());
- }
- }
- }
+ public static void HandleUpload(HttpContext context, int nodeId)
+ {
+ context.Response.Write(context.Request.Files.Count);
+
+ // loop through uploaded files
+ for (int j = 0; j < context.Request.Files.Count; j++)
+ {
+ // get parent node
+ Media parentNode = new Media(nodeId);
+
+ // get the current file
+ HttpPostedFile uploadFile = context.Request.Files[j];
+
+ // if there was a file uploded
+ if (uploadFile.ContentLength > 0)
+ {
+ // Get concrete MediaFactory
+ IMediaFactory factory = GetMediaFactory(uploadFile);
+
+ //Get the safe file name
+ string fileName = factory.SafeFileName(uploadFile.FileName);
+
+ // Create media Item
+ Media media = factory.CreateMedia(parentNode, uploadFile);
+
+ // Get path
+ int propertyId = media.getProperty("umbracoFile").Id;
+ string path = HttpContext.Current.Server.MapPath(factory.ConstructRelativeDestPath(propertyId));
+
+ // Create directory
+ if (UmbracoSettings.UploadAllowDirectories)
+ Directory.CreateDirectory(path);
+
+ // Save file
+ string filePath = Path.Combine(path, fileName);
+ uploadFile.SaveAs(filePath);
+
+ // Close stream
+ uploadFile.InputStream.Close();
+
+ // Save media
+ media.Save();
+ // Genereate xml cache
+ media.XmlGenerate(new XmlDocument());
+ }
+ }
+ }
// IDataEditor Members
// -------------------------------------------------------------------------
diff --git a/src/noerd.Umb.DataTypes.multipleFileUpload/noerd.Umb.DataTypes.multipleFileUpload.csproj b/src/noerd.Umb.DataTypes.multipleFileUpload/noerd.Umb.DataTypes.multipleFileUpload.csproj
index 39362cb..b3d072a 100644
--- a/src/noerd.Umb.DataTypes.multipleFileUpload/noerd.Umb.DataTypes.multipleFileUpload.csproj
+++ b/src/noerd.Umb.DataTypes.multipleFileUpload/noerd.Umb.DataTypes.multipleFileUpload.csproj
@@ -10,7 +10,7 @@
Properties
noerd.Umb.DataTypes.multipleFileUpload
noerd.Umb.DataTypes.multipleFileUpload
- v3.5
+ v4.0
2.0