2010-03-23 59 views
14

这看起来应该很容易,但我一直无法使它工作。我不知道为什么它不。它只是显示正常的文件输入。上传Uploadify使用C#

有没有任何代码/例子来得到这个工作。我感到沮丧...

谢谢大家。

+1

什么是uploadify?你有什么问题?你有试过的自己的示例代码吗? – 2010-03-23 15:17:40

+0

jQuery插件,我认为... – hunter 2010-03-23 15:17:58

+0

Uploadify很棒。 @JoelMartinez:http://www.uploadify.com/ – 2010-03-23 15:22:45

回答

19

这是关于如何开始使用C#和Webforms的视频教程,应该对您有所帮助。

http://casonclagg.com/articles/6/video-tutorial-uploadify-asp-net-c-sharp.aspx

您可以发布您的代码,虽然这样我也许能告诉你什么是你做错了什么?

下面是示例代码,我有asp.net

<script type="text/javascript"> 
     // <![CDATA[ 
     var id = "55"; 
     var theString = "asdf"; 
     $(document).ready(function() { 
     $('#fileInput').uploadify({ 
     'uploader': 'uploadify/uploadify.swf', 
     'script': 'Upload.ashx', 
     'scriptData': { 'id': id, 'foo': theString}, 
     'cancelImg': 'uploadify/cancel.png', 
     'auto': true, 
     'multi': true, 
     'fileDesc': 'Image Files', 
     'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg', 
     'queueSizeLimit': 90, 
     'sizeLimit': 4000000, 
     'buttonText': 'Choose Images', 
     'folder': '/uploads', 
     'onAllComplete': function(event, queueID, fileObj, response, data) { 

     } 
    }); 
    }); 
    // ]]></script> 

    <input id="fileInput" name="fileInput" type="file" /> 

然后你想一个处理程序(ashx的):

public class Upload : IHttpHandler, IRequiresSessionState 
{ 

    public void ProcessRequest(HttpContext context) 
    { 
     try 
     { 
      HttpPostedFile file= context.Request.Files["Filedata"]; 

      int id = (Int32.Parse(context.Request["id"])); 
      string foo = context.Request["foo"]; 
      file.SaveAs("C:\\" + id.ToString() + foo + file.FileName); 

      context.Response.Write("1"); 
     } 
     catch(Exception ex) 
     { 
      context.Response.Write("0"); 
     } 
    } 
} 

发布您的代码,我会看看在它。听起来就像你指向一个不存在的资源。也许你的'uploader'属性没有指向适当的资源,或者你的jquery链接被破坏(或不存在)。

+0

优秀,像魅力一样工作 – 2011-06-24 20:31:56

+3

视频已被删除! :( – Dave 2012-05-07 01:11:21

+0

只是提醒说,这个答案中描述的很多参数已经改变了,我建议总是检查最新的文档。 – 2013-08-08 14:47:49