uploadify控件使用在.net

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

     下面是成品的在.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

  

转载于:https://www.cnblogs.com/bellablog/p/4387549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值