1

I am using the jQuery Uploadify plugin on a web page to transfer files from the local computer to an ASP.NET MVC2 control action method. Is there a way to transfer the creation date/time of the file to the server?

I can get at the data in an Uploadify event on the client, but can not figure out how to "package" that data so it is moved to the server w/ the file.

Any thoughts appreciated.

ChrisP
  • 9,796
  • 21
  • 77
  • 121

1 Answers1

2

Try using onSelect event to add values to the scriptData object.

UPDATE: The following is an ad-hoc view to pass the data to the action. It appears that modificationDate returns a Unix timestamp in it's time field and you'll have to convert it on the server side. I wasn't able to find any documentation on modificationDate property.

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Home</title><link href="/Scripts/uploadify.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="/Scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="/Scripts/swfobject.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.uploadify.v2.1.4.min.js"></script>
    <script type="text/javascript">
        var myScriptData = {};
        $(document).ready(function () {
            $('#file_upload').uploadify({
                'uploader': '/Scripts/uploadify.swf',
                'script': '/Test/Upload',
                'cancelImg': '/Scripts/cancel.png',
                'folder': '/App_Data',
                'auto': true,
                'onSelect': function (event, ID, fileObj) {
                    $('#file_upload').uploadifySettings('scriptData', {
                        modifiedTimestamp: fileObj.modificationDate.time
                    });
                    return true;
                }
            });
            $('#file_upload').uploadifySettings('scriptData', myScriptData);
        });
    </script>
</head>
<body>
    <input id="file_upload" name="file_upload" type="file" />
</body>
</html>

In your action method, you can grab timestamp through the Request.Form["modifiedTimestamp"]. Check here on how to convert timestamp to the DateTime object.

Community
  • 1
  • 1
Artem Koshelev
  • 10,548
  • 4
  • 36
  • 68
  • Thanks Artem. This provides good info on how to approach the solution. I'll confirm after trying to implement it. – ChrisP Dec 23 '10 at 16:34
  • Finally got around to implementing this suggestion which worked well. One thing to note is the timestamp value is in milliseconds which is important when converting to the DateTime object. Also, modificationDate has regular date properties like .fullYear etc. – ChrisP Jan 06 '11 at 19:15