开发者

How to get file creation date on server for jQuery/uploadify?

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 d开发者_开发技巧ate/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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜