For one of my current projects, I have a requirement to pick a file from an existing directory (still within the web-app/root) ... does anyone know if there is already a "File Picker" data-type out there? (or should I just go ahead and develop one?)
The example here is that my client has an organised folder structure of PDFs, which need to be associated with specific content pages (Umbraco nodes). I was originally going to use the Media Picker / File Upload ... but the client wants to keep their folder structure (for organisational purposes) - so I need to work with it.
Any ideas, suggestions? (Currently thinking of a data-type that acts the same as Content/Media picker, but shows the file-system instead)
The package creator has a file picker (to include files to the package), It should be pretty simple to start from this code and create a file picker datatype.
A nice option on the file picker would be to set the root directory
Thanks for the pointer Tim... all the hard-work is done in the 'directoryBrowser.aspx'.
Here's what I quickly came up with - using the AbstractDataEditor class:
namespace Bodenko.Umbraco.DataType.FilePicker
{
using System;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.datatype;
public class FilePickerDataEditor: AbstractDataEditor
{
private TextBox control = new TextBox();
public FilePickerDataEditor()
{
this.RenderControl = this.control;
this.control.Init += new EventHandler(this.control_Init);
this.DataEditorControl.OnSave += new AbstractDataEditorControl.SaveEventHandler(this.DataEditorControl_OnSave);
}
public override Guid Id
{
get
{
return new Guid("318a9c2e-3966-4979-8c1d-575c5d5f669b");
}
}
public override string DataTypeName
{
get
{
return "File Picker";
}
}
private void control_Init(object sender, EventArgs e)
{
this.control.CssClass = "guiInputText";
this.control.Style.Add("width", "330px");
this.control.Text = this.Data.Value != null ? this.Data.Value.ToString() : String.Empty;
// create the image
HtmlImage image = new HtmlImage();
image.Src = "images/foldericon.png";
image.Style.Add("padding-left", "5px");
// create the anchor link
HtmlAnchor anchor = new HtmlAnchor();
anchor.HRef = "javascript:void(0);";
anchor.Attributes.Add("onclick", String.Format("javascript:top.openModal('developer/packages/directoryBrowser.aspx?target={0}', 'Choose a file or a folder', 400, 500); return false;", this.control.ClientID));
// add the image to the anchor link
anchor.Controls.Add(image);
// add the anchor link to the data-type property
this.control.Parent.Controls.Add(anchor);
}
private void DataEditorControl_OnSave(EventArgs e)
{
this.Data.Value = this.control.Text;
}
}
}
Once I've ironed out any bugs (and finished what I need to on my current project), I'll package up this data-type and release it as a project. :-)
Does a File Picker data-type exist?
Hi all,
For one of my current projects, I have a requirement to pick a file from an existing directory (still within the web-app/root) ... does anyone know if there is already a "File Picker" data-type out there? (or should I just go ahead and develop one?)
The example here is that my client has an organised folder structure of PDFs, which need to be associated with specific content pages (Umbraco nodes). I was originally going to use the Media Picker / File Upload ... but the client wants to keep their folder structure (for organisational purposes) - so I need to work with it.
Any ideas, suggestions? (Currently thinking of a data-type that acts the same as Content/Media picker, but shows the file-system instead)
Thanks, Lee.
Comment author was deleted
Hi Lee,
The package creator has a file picker (to include files to the package), It should be pretty simple to start from this code and create a file picker datatype.
A nice option on the file picker would be to set the root directory
Cheers,
Tim
Thanks for the pointer Tim... all the hard-work is done in the 'directoryBrowser.aspx'.
Here's what I quickly came up with - using the AbstractDataEditor class:
Once I've ironed out any bugs (and finished what I need to on my current project), I'll package up this data-type and release it as a project. :-)
Cheers, Lee.
Comment author was deleted
Sweet, even easier then I thought
Nice Lee!
Hey Lee,
I have used your solution and it works very well. Thanks.
is working on a reply...