第一次是博客,还有丢丢小兴奋呢。作为一个资深菜鸟,为了给自己留下点什么,开始记录一些技术问题。当然也是学习过程。

     下面是成品的在.net web下的应用,还有很多不足的地方,期待大家的点评。

$(document).ready(function()
        {
           $("#uploadify").uploadify({
                'buttonText':'选择文件',
                'swf': '../scripts/jquery.uploadify-v3.2/uploadify.swf?ver=<%=DateTime.Now.Ticks %>',
                'uploader': 'UploadHandler.aspx',//上传后对文件的处理页
                'auto': false,//是否自动上传
                'multi': true,//是否可以上传多个文件
                'fileSizeLimit' : 204800,
                'method' : "POST",
                'formData' : {'fileID' : <%="'"+Request["file_id"] + "'"%>},
                'onSelect': function(fileObj)
                {
                    if(fileObj.name.indexOf('%') < 0)
                    {//这是我自己应用的一个方法,在数据库里判断是否有重复文件。
                        ajaxSendPost('IsFileExist.aspx',<%= "'file_id=" + Request["file_id"] + "'"%> + '&file_name=' + fileObj.name + '&file_size='+fileObj.size,IsFileExist);
                    }
                    else
                    {
                        $('#uploadify').uploadify('cancel', '*');
                        alert("文件名中含有非法字符(%)");
                    }
                },
                'onUploadSuccess':function(file,data,response){//处理上传成功后的事件
                    
                },
               
                'onCancel':function(){//取消上传或者点击右上角X的方法
                   
                }
               
            });
           
            function IsFileExist(){
                if(ajaxHttpRequest.readyState==4&&ajaxHttpRequest.status==200){
                    if(ajaxHttpRequest.responseText == "2")
                    {
                        alert("文件已经存在,按上传将覆盖已有文件!");
                    }
                    else if (ajaxHttpRequest.responseText == "1")
                    {
                        $('#uploadify').uploadify('cancel', '*');
                        alert("文件已经存在!");
                    }
                }
            }
        });

  cs文件处理:(UploadHandler.aspx.cs)

  protected void Page_Load(object sender, EventArgs e)     {

  HttpPostedFile PostedFile = Request.Files["Filedata"];

     string VirtualDIR = ConfigurationManager.AppSettings["VirtualDIR"];

   string uploadPath = HttpContext.Current.Server.MapPath(VirtualDIR);

    string AttchementuploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Attchements/");

    string MemouploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Memos/");

     string EvaluationUploadPath = HttpContext.Current.Server.MapPath(VirtualDIR + "/Evaluations/");

  DateTime TimeStamp = DateTime.Now;

   if (PostedFile != null)

     {

         if (!string.IsNullOrEmpty(Request["fileID"]))

         {

           int file_id = int.Parse(Request["fileID"]);

           string FullFileName = uploadPath + "\\" + PostedFile.FileName;

        if (!Directory.Exists(uploadPath))

           {

             Directory.CreateDirectory(uploadPath);

           }

          PostedFile.SaveAs(FullFileName);

//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失

       //context.Session[context.Session["userName"].ToString()] = filename;

//context.Response.Write(filename);

   string content = SaveFileContent.GetFileContent(FullFileName);

}

       else

        {

                     Response.Write("0");

          }

}

  }

  else

     {

       Response.Write("0");

     }

}

  

顺便把保存文件内容的方法写在这个了(只适合.txt和word文件啦)

public class SaveFileContent     {

   public SaveFileContent()

     {             //             // TODO: 在此处添加构造函数逻辑             //

    }

public static string GetFileContent(object file_path)

{             string outText = string.Empty;

Word._Application oWord = new Word.Application();

    Word._Document oDoc;

object oMissing = System.Reflection.Missing.Value;

    object format = WdSaveFormat.wdFormatDocument;

    object VisiableWindows = false;

object Readonly = true;

try             {

oWord.Visible = true;

object fileName = file_path;

oDoc = oWord.Documents.Open(ref fileName, ref format, ref Readonly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref VisiableWindows, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

outText = oDoc.Content.Text;

oDoc.Close(ref oMissing, ref oMissing, ref oMissing);

oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref VisiableWindows);

//oDoc = oWord.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);

return outText.ToString();

}

catch (Exception ex)

{

Console.Write(ex.Message);

}

finally

{

oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

}

return "";

}

}

就不展示结果啦~~

把3.2的具体参数放在这了,以便查找!!

http://blog.sina.com.cn/s/blog_5079086b0101fkmh.html

  

uploadify控件使用在.net的更多相关文章

  1. Uploadify 控件上传图片 + 预览

    jquery的Uploadify控件上传图片和预览使用介绍. 在简单的servlet系统中和在SSH框架中,后台处理不同的,在三大框架中图片预览时费了不少力气,所以下面将两种情况都介绍一下. 1,前台 ...

  2. ThinkPHP 3.2.3集成uploadify上传控件

    uploadify控件有一个坑爹的问题,就是文件上传时会session丢失,官方解释http://www.uploadify.com/documentation/uploadify/using-ses ...

  3. jquery文件上传控件 Uploadify

    (转自 http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html) 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同 ...

  4. 使用Uploadify(UploadiFive)多文件上传控件遇到的坑

    最近项目中需要实现多文件上传功能,于是结合需求最终选择了Uploadify这一款控件来实现.相比其他控件,Uploadify具有简洁的界面,功能API基本可以解决大多数需求,又是基于jquery的,配 ...

  5. jquery文件上传控件 Uploadify 问题记录

    Uploadify v3.2.1 首先引用下面的文件 <!--上传控件 uploadify--> <script type="text/javascript" s ...

  6. jquery上传文件控件Uploadify

    基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. 要求使用jquery1.4或以上版本,flash player 9.0.24以上. 有两个 ...

  7. uploadify上传控件使用

    uploadify是JQuery的一个上传插件,实现的效果非常不错,并且带进度显示,我将给大家演示如何使用uploadify进行图片上传, 1.点我下载http://www.uploadify.com ...

  8. 文件上传~Uploadify上传控件~续(多文件上传)

    对于Uploadify文件上传之前已经讲过一次(文件上传~Uploadify上传控件),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Upload ...

  9. uploadify上传控件中文的乱码解决办法

    uploadify上传控件中文的乱码解决办法 网站用的gb2312的编码,用uploadify上传控件上传中文时在IE能部分成功,FF,Chrome则完全失败,查找了一天原因,结果发现是页面编码问题, ...

随机推荐

  1. python3 module中__init__.py的需要注意的地方

    网上关于__init__.py的作用的资料到处都是,我在此就不再啰嗦哪些了. 若有需要.请各位看官去搜搜即可. 最近刚开始用Python3 就遇到了这个比较有意思的事情 闲言少叙,下面要介绍的是pyt ...

  2. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  3. openssl 安装

    六.运行“nmake -f ms\ntdll.mak install”安装编译后的OpenSSL到指定目录. 七.查看安装结果C:\usr\local\ssl或C:\openssl-0.9.8.e下包 ...

  4. javascript 高级程序设计学习笔记(面向对象的程序设计) 2

    在调用构造函数时会为实例添加一个指向最初原型的指针,我们可以随时为原型添加属性和方法,并且能在实例中体现出来,但如果是重新了原型对象,那就会切断构造函数与最初原型的联系. function Dog ( ...

  5. VS2003.NET在文件中查找卡死

    不知怎么的,安装vs2003后,一点查找就卡死. 修复方法:修改devenv.exe的兼容性配置,勾选“禁用视觉主题”! 说实话,还真不知道这两者有什么关系?

  6. 在world中批量调整图片的大小

    1.Alt+F8调出vb宏  创建一个宏名字,setsize 粘贴代码后保存关闭. Sub setsize() ' ' setsize 宏 ' ' Dim iSha As InlineShape Fo ...

  7. html 调用 activeX(c++)

    1.新建MFC ActiveX 2.添加方法 3.找到add函数编写代码 4.在test.idl中找到最后一个uuid 5.编译工程,会自动注册控件 6.html中的代码 <html> & ...

  8. Oracle学习之常见错误整理

    一.ORA-12154: TNS: 无法解析指定的连接标识符 在程序中连接Oracle数据库的方式与其他常用数据库,如:MySql,Sql Server不同,这些数据库可以通过直接指定IP的方式连接, ...

  9. Computer Transformation(hdoj 1041)

    Problem Description A sequence consisting of one digit, the number 1 is initially written into a com ...

  10. Android Studio 如何导入第三方jar 包

    第一步: 将第三方jar包加入到libs文件夹中 第二步: 分为两种情况 第一种是打开工程所在Project Structure,然后选择Dependencies,点击那个加号选择File Depen ...