软件世界网 购物 网址 三丰软件 | 小说 美女秀 图库大全 游戏 笑话 | 下载 开发知识库 新闻 开发 图片素材
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
移动开发 架构设计 编程语言 Web前端 互联网
开发杂谈 系统运维 研发管理 数据库 云计算 Android开发资料
  软件世界网 -> 编程语言 -> C#+一般处理程序+jquery.uploadify上传XML文件并插入数据库中 -> 正文阅读
编程语言 最新文章
Java面试题(1)
ReactiveX序列——RxSwift
C++STL之ACM相关知识大全
c++中vector向量几种情况的总结(向量指针,
SSH框架整合demo
JAX
UVA
curl备忘(1)
C#机房重构——万事开头难(二)
OJ刷题

[编程语言]C#+一般处理程序+jquery.uploadify上传XML文件并插入数据库中

  2016-04-03 20:44:21

效果如图:
上传前

上传中

HTML代码:
    <div class="widget-content nopadding">
                                        <table class="table table-bordered table-striped">
                                                <tbody>

                                               <tr class="odd gradeC">
                                                      <td>上传XML列表:</td>
                                                        <td style="text-align: left">
                                           <div id="fileQueue" class="fileQueue" style="width: 670px; height: 100px;"></div> </td>
                                                    <td> <input type="file" name="file_upload" id="file_upload" /></td>
                                                 </tr>

                                                         <tr class="even gradeX"><td colspan="3"> <p>
                                                           <input type="button" class="btn btn-info" id="btnUpload" onclick="doUpload()" value="上传" />
                                                                
                           <input type="button" class="btn btn-info" id="btnCancelUpload" onclick="$('#file_upload').uploadify('cancel')" value="取消" />
                                                             </p>
                                                           <div id="div_show_files"></div>
                                                          </td>
                                                         </tr>
                                                        </tbody>
                                                     </table>
        </div>   </div>      

JS参照引用:
  
  <script src="assets/js/jquery-1.8.2.min.js"></script>
        <!--引入uploadify-->
        <script type="text/Javascript" src="plugins/uploadify/jquery.uploadify.js"></script>
        <link type="text/css" href="plugins/uploadify/uploadify.css" rel="stylesheet" />

        <script type="text/javascript">
            $(function () {
                var guid = '<%=Request["guid"] %>';
            var type = '<%=Request["type"] %>';
            if (guid == null || guid == "") {
                guid = newGuid();
            }
            if (type != null) {
                type = type + '/';
            }

            $('#file_upload').uploadify({
                'swf': 'plugins/uploadify/uploadify.swf',              //FLash文件路径
                'buttonText': '浏  览',                        //按钮文本
                'uploader': 'uploadhandler.ashx?guid=' + guid, //处理ASHX页面
                'formData': { 'folder': 'picture', 'isCover': 1 },         //传参数
                'queueID': 'fileQueue',                        //队列的ID
                'queueSizeLimit': 999,                          //队列最多可上传文件数量,默认为999
                'auto': false,                                 //选择文件后是否自动上传,默认为true
                'multi': true,                                 //是否为多选,默认为true
                'removeCompleted': true,                       //是否完成后移除序列,默认为true
                'fileSizeLimit': '0',                          //单个文件大小,0为无限制,可接受KB,MB,GB等单位的字符串值
                'fileTypeDesc': 'All Files',                   //文件描述
                'fileTypeExts': '*.xml',                         //上传的文件后缀过滤器
                'onQueueComplete': function (queueData) {      //所有队列完成后事件
                    if (queueData.queueLength>0) alert("上传完毕!");
                },
                'onError': function (event, queueId, fileObj, errorObj) {
                    alert(errorObj.type + ":" + errorObj.info);
                },
                'onUploadStart': function (file) {
                },
                'onUploadSuccess': function (file, data, response) {   //一个文件上传成功后的响应事件处理
                    // var data = $.parseJSON(data);//如果data是json格式
                    //var errMsg = "";
                    if ($.parseJSON(data) == 2) {
                        alert("目录UpLoadImg/ChannelTvXML不存在或名称不对!"); return false;
                    }
                }

            });
        });

        function newGuid() {
            var guid = "";
            for (var i = 1; i <= 32; i++) {
                var n = Math.floor(Math.random() * 16.0).toString(16);
                guid += n;
                if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
                    guid += "-";
            }
            return guid;
        }

        //执行上传
        function doUpload() {
            $('#file_upload').uploadify('upload', '*');
        }
        </script>


C# 一般处理程序代码:    UploadHandler.ashx
      public class UploadHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Request.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            context.Response.Charset = "UTF-8";

            if (context.Request.Files.Count > 0)
            {
                #region 获取上传路径
                string uploadFolder = GetUploadFolder();
                #endregion

                if (System.IO.Directory.Exists(uploadFolder))
                {//如果上传路径存在
                    HttpPostedFile file = context.Request.Files["Filedata"];
                    string filePath = Path.Combine(uploadFolder, file.FileName);
                    file.SaveAs(filePath);
                    List<ChannelListInfo> channellist = GetXmlNodeInformation(filePath);
                    using (GoodLookDataContext db = new GoodLookDataContext())
                    {
                        
                        //  Insert this List<> of records using a Bulk Insert
//利用BulkCopyToDatabase 批量插入数据库中必须保持channellist和数据库中字段完全一致,大小写,否则报错。
                       DataTableHelper.BulkCopyToDatabase(channellist, "channeltvlist", db);
                     
                    }
                    SearchDataClass.DeleteDir(filePath);
                    context.Response.Write("0");
                }
                else
                {
                    context.Response.Write("2");
                }
            }
        }
       public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private static List<ChannelListInfo> GetXmlNodeInformation(string xmlPath)
        {
            List<ChannelListInfo> tvlist = new List<ChannelListInfo>();
            try
            {
                //定义并从xml文件中加载节点(根节点)
                XElement rootNode = XElement.Load(xmlPath);
                //查询语句: 获得根节点下name子节点(此时的子节点可以跨层次:孙节点、重孙节点)
                var channeltv = rootNode.Element("channel").Attribute("name").Value;
                tvlist = (from p in rootNode.Descendants("program")
                          orderby p.Element("start").Value ascending
                          select new ChannelListInfo
                          {
                              WeekDate = CaculateWeekDay(DateTime.Parse(p.Element("start").Value).Year,
 DateTime.Parse(p.Element("start").Value).Month, DateTime.Parse(p.Element("start").Value).Day),
                              ChannelTV = channeltv,
                              ChannelPlayDate=DateTime.Parse(p.Element("start").Value) ,
                              ChannelStartDate = DateTime.Parse(p.Element("start").Value),
                              ChannelEndDate = DateTime.Parse(p.Element("end").Value),
                              ChannelName = p.Element("name").Value,
                              ChannelType = p.Element("type").Value,
                              ChannelSummary = p.Element("summary").Value,
                          }).ToList<ChannelListInfo>();

            }
            catch { }
            return tvlist;
        }

        /// 基姆拉尔森计算公式计算日期
        /// </summary>
        /// <param name="y">年</param>
        /// <param name="m">月</param>
        /// <param name="d">日</param>
        /// <returns>星期几</returns>

        protected static string CaculateWeekDay(int y, int m, int d)
        {
            if (m == 1 || m == 2)
            {
                m += 12;
                y--;         //把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公式计算。
            }
            int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
            string weekstr = "";
            switch (week)
            {
                case 0: weekstr = "星期一"; break;
                case 1: weekstr = "星期二"; break;
                case 2: weekstr = "星期三"; break;
                case 3: weekstr = "星期四"; break;
                case 4: weekstr = "星期五"; break;
                case 5: weekstr = "星期六"; break;
                case 6: weekstr = "星期日"; break;
            }
            return weekstr;
        }
    

        /// <summary>
        /// 获取上传目录
        /// </summary>
        /// <returns></returns>
        public static string GetUploadFolder()
        {
            string rootPath = HttpContext.Current.Server.MapPath("~");
            return Path.Combine(rootPath, "UpLoadImg/ChannelTvXML");
        }

    }
 
    public class ChannelListInfo
    {
     //   public string ChannelID { get; set; }
        public string WeekDate { get; set; }
        public string ChannelTV { get; set; }
        public string ChannelName { get; set; }
        public string ChannelType { get; set; }
        public string ChannelSummary { get; set; }
     //   public string ChannelImg { get; set; }

        public DateTime ChannelStartDate { get; set; }
        public DateTime ChannelEndDate { get; set; }
     //   public DateTime? AddTime { get; set; }
        public DateTime? ChannelPlayDate { get; set; }
        public int FatherTvNameID { get; set; }

    }





XML:格式
<?xml version="1.0" encoding="UTF-8"?>
<epg>
  <channel name="BTV-1(高清)">
    <program>
      <start>2016-03-25 00:48:00</start>
      <end>2016-03-25 00:50:00</end>
      <name>晚间气象服务</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 00:50:00</start>
      <end>2016-03-25 00:53:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 00:53:00</start>
      <end>2016-03-25 01:38:00</end>
      <name>中国骑兵</name>
      <type>战争</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 01:38:00</start>
      <end>2016-03-25 01:39:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 01:39:00</start>
      <end>2016-03-25 02:24:00</end>
      <name>中国骑兵</name>
      <type>战争</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 02:24:00</start>
      <end>2016-03-25 02:25:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 02:25:00</start>
      <end>2016-03-25 03:10:00</end>
      <name>中国骑兵</name>
      <type>战争</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 03:10:00</start>
      <end>2016-03-25 03:55:00</end>
      <name>中国骑兵</name>
      <type>战争</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 03:55:00</start>
      <end>2016-03-25 04:40:00</end>
      <name>中国骑兵</name>
      <type>战争</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 04:40:00</start>
      <end>2016-03-25 04:42:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 04:42:00</start>
      <end>2016-03-25 05:42:00</end>
      <name>养生堂</name>
      <type>健康</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 05:42:00</start>
      <end>2016-03-25 06:00:00</end>
      <name>法治进行时</name>
      <type>法制/社会</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:00:00</start>
      <end>2016-03-25 06:01:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:01:00</start>
      <end>2016-03-25 06:19:00</end>
      <name>法治进行时</name>
      <type>法制/社会</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:19:00</start>
      <end>2016-03-25 06:20:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:20:00</start>
      <end>2016-03-25 06:55:00</end>
      <name>养生堂精编版</name>
      <type>健康</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:55:00</start>
      <end>2016-03-25 06:57:00</end>
      <name>早间气象服务</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 06:57:00</start>
      <end>2016-03-25 07:00:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 07:00:00</start>
      <end>2016-03-25 09:00:00</end>
      <name>北京您早</name>
      <type>时政</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 09:00:00</start>
      <end>2016-03-25 09:06:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 09:06:00</start>
      <end>2016-03-25 10:11:00</end>
      <name>精品栏目荟萃</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 10:11:00</start>
      <end>2016-03-25 10:17:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 10:17:00</start>
      <end>2016-03-25 11:01:00</end>
      <name>芈月传</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 11:01:00</start>
      <end>2016-03-25 11:09:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 11:09:00</start>
      <end>2016-03-25 11:54:00</end>
      <name>芈月传</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 11:54:00</start>
      <end>2016-03-25 12:00:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 12:00:00</start>
      <end>2016-03-25 12:58:00</end>
      <name>特别关注</name>
      <type>法制/社会</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 12:58:00</start>
      <end>2016-03-25 13:00:00</end>
      <name>午间气象服务</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 13:00:00</start>
      <end>2016-03-25 13:08:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 13:08:00</start>
      <end>2016-03-25 13:53:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 13:53:00</start>
      <end>2016-03-25 14:01:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 14:01:00</start>
      <end>2016-03-25 14:44:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 14:44:00</start>
      <end>2016-03-25 14:52:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 14:52:00</start>
      <end>2016-03-25 15:35:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 15:35:00</start>
      <end>2016-03-25 15:44:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 15:44:00</start>
      <end>2016-03-25 16:27:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 16:27:00</start>
      <end>2016-03-25 16:35:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 16:35:00</start>
      <end>2016-03-25 17:20:00</end>
      <name>暖暖的味道精华版</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 17:20:00</start>
      <end>2016-03-25 17:25:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 17:25:00</start>
      <end>2016-03-25 18:25:00</end>
      <name>养生堂</name>
      <type>健康</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 18:25:00</start>
      <end>2016-03-25 18:30:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 18:30:00</start>
      <end>2016-03-25 18:55:00</end>
      <name>北京新闻</name>
      <type>时政</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 18:55:00</start>
      <end>2016-03-25 19:00:00</end>
      <name>天气预报</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 19:00:00</start>
      <end>2016-03-25 19:30:00</end>
      <name>转播中央台新闻联播</name>
      <type>时政</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 19:30:00</start>
      <end>2016-03-25 19:33:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 19:33:00</start>
      <end>2016-03-25 20:18:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 20:18:00</start>
      <end>2016-03-25 20:22:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 20:22:00</start>
      <end>2016-03-25 21:07:00</end>
      <name>猎人</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 21:07:00</start>
      <end>2016-03-25 21:09:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 21:09:00</start>
      <end>2016-03-25 21:11:00</end>
      <name>大剧抢先看</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 21:11:00</start>
      <end>2016-03-25 21:12:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 21:12:00</start>
      <end>2016-03-25 22:42:00</end>
      <name>二胎时代</name>
      <type></type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 22:42:00</start>
      <end>2016-03-25 22:46:00</end>
      <name>广宣时段</name>
      <type>生活服务</type>
      <summary></summary>
    </program>
    <program>
      <start>2016-03-25 22:46:00</start>
      <end>2016-03-26 00:16:00</end>
      <name>二胎时代</name>
      <type></type>
      <summary></summary>
    </program>
   
  </channel>
</epg>

上一篇文章      下一篇文章      查看所有文章
2016-04-03 20:43:25  
360图书馆 论文大全 母婴/育儿 软件开发资料 网页快照 文字转语音 购物精选 软件 美食菜谱 新闻中心 电影下载 小游戏 Chinese Culture
生肖星座解梦 三沣玩客 拍拍 视频 开发 Android开发 站长 古典小说 网文精选 搜图网 天下美图 中国文化英文 多播视频 装修知识库
2017-1-22 7:43:07
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  软件世界网 --