Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stephen Kiers 41 posts 62 karma points
    Jul 28, 2010 @ 00:29
    Stephen Kiers
    0

    Very General Beginner Questions

    I am a designer, not a coder. I work for a IT Company though so I have ASP.Net developers at my disposal.

    My questions are:

    1. Is node data stored in the database at all, or just in the umbraco.config file?
    2. Can I attach an ASP.Net action to a 'Data Type' action?
      1. Ex. Add a action that when a file is uploaded a ASP.Net page checks if it is a zip with jpgs and, if it is, creates subnodes for each image
    3. Can I do #2 with XSLT only?
    4. Where could I learn this? Documentation?
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 28, 2010 @ 00:59
    Aaron Powell
    0

    Yes the data is stored in the database, that is where the history of changes gets stored. It's then converted into XML and the XML is then stored in the database. The XML is then written to the file system and loaded into memory, so there's several levels of storage.

    Generally you'll only be working against the XML cache.

    For your 2nd question you can use Umbraco events to detect if you've uploaded a ZIP file and then manipulate it. You can't do that without .NET though, XSLT is a markup language not a programming language really.

  • Bex 444 posts 555 karma points
    Jul 28, 2010 @ 09:49
    Bex
    0

    Hi Stephen!

    Another way you could make your datatype check if it's a zip with jpgs would be to create a custom datatype.

    I made a simple custom upload that validates if the files uploaded are flv files, but you would need something a bit more complex to check if your zip file contains jpgs, but your c# developers could easily do this for you.

    I have created a user control to create my datatype;
    If you'd like to do it this way to get you started here's my code.

    The ascx file

    <script type="Text/Javascript">
        var extArray = new Array(".flv");
    
    
        function ValidateFile() {
            var upload = document.getElementById('<%= FileUploadControl.ClientID%>');
            var filename = upload.value;
            var allowSubmit = false;
            if (!filename) return;
            while (filename.indexOf("\\") != -1)
                filename = filename.slice(filename.indexOf("\\") + 1);
            ext = filename.slice(filename.indexOf(".")).toLowerCase();
            for (var i = 0; i < extArray.length; i++) {
                if (extArray[i] == ext) { allowSubmit = true; break; }
            }
            if (allowSubmit) {
                return true;
            }
            else {
                alert("Your file type is invalid. You can only upload the following types:\n "
    + (extArray.join("  ")) + "\nPlease select a new "
    + "file to upload and submit again.");
                return false;
            }
        }
    
    
        function CheckFile() {
    
            var upload = document.getElementById('<%= FileUploadControl.ClientID%>');
            var filename = upload.value;
            if (filename != '') {
                var valid = false;
                while (filename.indexOf("\\") != -1)
                    filename = filename.slice(filename.indexOf("\\") + 1);
                ext = filename.slice(filename.indexOf(".")).toLowerCase();
    
                for (var i = 0; i < extArray.length; i++) {
                    if (extArray[i] == ext) { valid = true; break; }
                }
    
                if (!valid) {
                    ClearFileUpload(upload);
                    alert("Your file type is invalid. \nYou can only upload the following types: "
    + (extArray.join("  ")) + "\nPlease select a new "
    + "file to upload and submit again.");
                }
            }
        }
        function ClearFileUpload(upload) {
    
            upload.select();
            n = upload.createTextRange();
            n.execCommand('delete');
            upload.focus();
    
        }
    
    
    </script>
    
    <asp:FileUpload ID="FileUploadControl" runat="server" onChange="CheckFile()" Width="200" />&nbsp;&nbsp;<asp:Label ID="VideoPathLabel" runat="server"></asp:Label>
    
    The code behind the ascx file
     public partial class VideoFileUpload : UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
        {
            public string umbracoValue;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                  //~~~my custom code to get the media folder I want to put the image in is here~~~
    
            
                        Media media = Media.MakeNew(FileUploadControl.FileName, mediaType, User.GetUser(0), galleryFolder.Id);
                        string mediaFolderName = HttpContext.Current.Server.MapPath(umbraco.GlobalSettings.Path + "/../media/" + media.Id);
                        Directory.CreateDirectory(mediaFolderName);
                        string fullMediaPath = Path.Combine(mediaFolderName, FileUploadControl.FileName);
    
               FileUploadControl.SaveAs(fullMediaPath);
    
                        string orgExt = (FileUploadControl.FileName.Substring(FileUploadControl.FileName.LastIndexOf(".") + 1,
                                                                      FileUploadControl.FileName.Length -
                                                                      FileUploadControl.FileName.LastIndexOf(".") - 1));
                        orgExt = orgExt.ToLower();
                        string ext = orgExt.ToLower();
                        try
                        {
                            media.getProperty("umbracoExtension").Value = ext;
                        }
                        catch
                        {
                        }
                        // Save file size
                        try
                        {
                            System.IO.FileInfo fi = new FileInfo(fullMediaPath);
                            media.getProperty("umbracoBytes").Value = fi.Length.ToString();
                        }
                        catch
                        {
                        }
                        string mediaPath = "/media/" + media.Id.ToString() + "/" + FileUploadControl.FileName;
    
                        media.getProperty("umbracoFile").Value = mediaPath;
                        media.XmlGenerate(new XmlDocument());
                        umbracoValue = mediaPath;
                        VideoPathLabel.Text = mediaPath;
                    }
    
                }
                else
                {
                    if (value.ToString() != string.Empty)
                    {
                        VideoPathLabel.Text = value.ToString();
                    }
                }
            }
    
            public object value
            {
                get
                {
                    return umbracoValue;
                }
                set
                {
                    umbracoValue = value.ToString();
                }
            }

     

    Then add this to the user controls folder in umbraco and reference it as a datatype.

    If you are considering doing it this way, I hope it helps! If you have any question let me know.

     

    Bex

Please Sign in or register to post replies

Write your reply to:

Draft