上传附件 读xml

     public static List<AirWaysInfo> GetAirWays()
        {
            try
            {
                if (AllAirWays.Count > 0)
                {
                    return AllAirWays;
                }
                else
                {
                    string ariPath = AppDomain.CurrentDomain.BaseDirectory + "//XML//AirLine.XML";//存放航空公司的文件  
                    if (!File.Exists(ariPath))
                    {
                        return null;
                    }
                    DataSet dsAirWays = new DataSet();
                    dsAirWays.ReadXml(ariPath);
                    if (dsAirWays.Tables.Count == 0)
                    {
                        return null;
                    }
                    else
                    {
                        foreach (DataRow dr in dsAirWays.Tables[0].Rows)
                        {
                            AirWaysInfo aw = new AirWaysInfo();
                            aw.Code = dr["value"].ToString();
                            aw.Name = dr["text"].ToString();
                            AllAirWays.Add(aw);
                        }
                    }
                    return AllAirWays;
                }
            }
            catch
            {
                return null;
            }
        }

 

  public static string GetAirlineByCode(string aircom)
        {
            List<AirWaysInfo> arrWays = GetAirWays();
            if (null != arrWays && arrWays.Count > 0)
            {
                var listQuary = from item in arrWays where item.Code == aircom select item.Name;
                if (listQuary.Count<string>() > 0)
                {
                    foreach (var v in listQuary)
                    {
                        return v.ToString();
                    }
                }
                else//如果查不到该航空公司则将字符串取前两位再次匹配
                {
                    string strlit = "";
                    if (aircom.Length > 2)
                    {
                        strlit = aircom.Substring(0, 2);
                    }
                    var listQuaryLit = from item in arrWays where item.Code == strlit select item.Name;
                    foreach (var v in listQuaryLit)
                    {
                        return v.ToString();
                    }
                    return "";
                }
            }
            else//xml文件不存在的情况
            {
                switch (aircom)
                {
                    case "MU":
                        aircom = "东方航空";

}

}

}

 

 

   #region 上传附件
            string path2 = "";
            if (!string.IsNullOrEmpty(fluAttachment.FileName))
            {
                //读取配置文件中文件上传的目的路径
                //string url = WebConfigurationManager.AppSettings["attachment"];

                //上传文件的完整路径
                string path = Path.Combine(HttpContext.Current.Server.MapPath("Attachment"), System.IO.Path.GetFileName(fluAttachment.FileName));

                //文件保存的文件夹
                string savePath = path.Substring(0, (path.Length - fluAttachment.FileName.Length));


                //保存在数据库中的路径
                path2 = "Attachment/" + fluAttachment.FileName;
                // hidUrl.Value = path2;

                /**判断文件夹是否存在**/
                if (System.IO.Directory.Exists(savePath))
                {
                    //判断该是否已经上传
                    if (System.IO.File.Exists(path))
                    {

                        path2 = "";
                    }
                    else
                    {
                        //进行上传操作  
                        fluAttachment.SaveAs(path);
                    }
                }
                else
                {
                    //不存在则创建文件夹  
                    System.IO.Directory.CreateDirectory(savePath);

                    fluAttachment.SaveAs(path);
                }


            }
            #endregion
            model.AttachmentURL = path2;

        protected string UploadFile()
        {
            #region 上传附件
            string path2 = "";
           
            if (!string.IsNullOrEmpty(fluAttachment.FileName))
            {
                //上传文件的完整路径
                string path = Path.Combine(HttpContext.Current.Server.MapPath("Attachment"), System.IO.Path.GetFileName(fluAttachment.FileName));

                FileInfo objFile = new FileInfo(fluAttachment.PostedFile.FileName);
                if (objFile.Extension == ".rar" || objFile.Extension == ".zip")
                {
                    if (objFile.Length > 3145728)
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "a1", "alert('上传文件超过指定大小,请选择3M以内的压缩文件上传');return;", true);
                    }
                    else
                    {
                        //文件保存的文件夹
                        string savePath = path.Substring(0, (path.Length - fluAttachment.FileName.Length));


                        //保存在数据库中的路径
                        path2 = "Attachment/" + fluAttachment.FileName;
                        // hidUrl.Value = path2;

                        /**判断文件夹是否存在**/
                        if (System.IO.Directory.Exists(savePath))
                        {
                            //进行上传操作  
                            fluAttachment.SaveAs(path);
                        }
                        else
                        {
                            //不存在则创建文件夹  
                            System.IO.Directory.CreateDirectory(savePath);

                            fluAttachment.SaveAs(path);
                        }
                    }
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "a2", "alert('上传文件类型不符合,请选择扩展名为rar或zip的文件上传');return;", true);
                }
               
            }
            return path2;
            #endregion
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值