Common下FileHelper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;

 

namespace Common
{
    public class FileHelper : Page
    {

        #region 获取滚动图片/广告图片列表
        /// <summary>
        /// 获取滚动图片/广告图片列表
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> GetRollImageList(string Path)
        {
            Dictionary<string, string> imglist = new Dictionary<string, string>();
            XmlDocument xml = new XmlDocument();
            xml.Load(Path);
            XmlNode root = xml.SelectSingleNode("image");
            XmlNodeList childlist = root.ChildNodes;
            foreach (XmlNode node in childlist)
            {
                imglist.Add(node.Attributes["path"].Value, node.ChildNodes[0].InnerText);
            }
            return imglist;
        }
        #endregion

        #region 滚动图片xml增加一个节点
        /// <summary>
        /// 滚动图片xml增加一个节点
        /// </summary>
        /// <param name="xmlpath"></param>
        /// <param name="imgpath"></param>
        /// <param name="href"></param>
        public static void AddNewXmlNode(string xmlpath, string imgname, string href, string imgpath)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(xmlpath);
            XmlNode root = xml.SelectSingleNode("image");
            XmlElement xe = xml.CreateElement("imageinfo");
            xe.SetAttribute("path", imgpath + imgname);
            XmlElement xe1 = xml.CreateElement("href");
            xe1.InnerText = href;
            xe.AppendChild(xe1);
            root.AppendChild(xe);
            xml.Save(xmlpath);
        }
        #endregion

        #region 滚动图片xml删除一个节点
        /// <summary>
        /// 滚动图片xml删除一个节点
        /// </summary>
        /// <param name="xmlpath"></param>
        /// <param name="imgpath"></param>
        public static void DelXmlNode(string xmlpath, string imgname, string imgpath)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(xmlpath);
            XmlNode root = xml.SelectSingleNode("image");
            XmlNodeList xnl = xml.SelectSingleNode("image").ChildNodes;
            foreach (XmlNode xn in xnl)
            {
                XmlElement xe = (XmlElement)xn;
                if (xe.GetAttribute("path") == imgpath + imgname)
                {
                    root.RemoveChild(xe);
                }
            }
            xml.Save(xmlpath);
        }
        #endregion

        #region 获取滚动图片列表
        /// <summary>
        /// 获取滚动图片列表
        /// </summary>
        /// <returns></returns>
        public string GetRollImage()
        {

            StringBuilder sb = new StringBuilder();
            Dictionary<string, string> list = FileHelper.GetRollImageList(Server.MapPath("~/sysconfig/RollImage.xml"));
            foreach (string key in list.Keys)
            {
                sb.Append("<a href=/"" + list[key] + "/"><img src=/"" + key.Replace("~/", "../") + "/" /></a>");
            }
            sb.Append("");

            return sb.ToString();
        }
        #endregion

        #region 删除图片
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="path"></param>
        public void DeleteImg(string path)
        {
            FileInfo file = new FileInfo(Server.MapPath(path));
            if (File.Exists(Server.MapPath(path)))
            {
                File.Delete(Server.MapPath(path));
            }
        }
        #endregion

        /// <summary>
        /// 上传文件
        /// </summary>
        /// <returns></returns>
        public string UpFile(FileUpload up, string oldFile,string filename)
        {
            string result = "";
            if (up.HasFile)
            {
                if (GetExtension(up.FileName)!= "exe")
                {
                    string fileName = up.FileName;
                    string JueDuiUrl = Server.MapPath("~/" + filename + "");
                    string xiangduiurl = "~/" + filename + "" + "/" + fileName;

                    if (!Directory.Exists(JueDuiUrl))
                    {
                        Directory.CreateDirectory(JueDuiUrl);//如果不存在,则创建
                    }
                    string webFilePath = JueDuiUrl + "//" + fileName;        // 服务器端文件路径  
                    if (!File.Exists(webFilePath))
                    {
                        if (!string.IsNullOrEmpty(oldFile))
                        {
                            new Common.FileHelper().DeleteImg(oldFile);
                        }
                        up.SaveAs(webFilePath);
                        result = xiangduiurl;
                    }
                    else
                    {
                        return "1";
                    }
                }
                else
                {
                    return "2";
                }
            }
            return result;
        }

        /// <summary>
        /// 获取文件扩展名
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetExtension(string fileName)
        {
            int i = fileName.LastIndexOf(".") + 1;
            string Name = fileName.Substring(i);
            return Name;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NullReferenceException: Object reference not set to an instance of an object BattleStageControl.OpenBattleRewardNext () (at Assets/0.C#/Battle/BattleStageControl.cs:102) BattleStageControl.OpenBattleReward () (at Assets/0.C#/Battle/BattleStageControl.cs:70) EventCenter.Broadcast (MeventType MeventType) (at Assets/0.C#/Common/EventCenter.cs:162) FuguiState.DeleteFugui02 (System.String site, System.String FuguiName) (at Assets/0.C#/Map/FuguiState.cs:231) EventCenter.Broadcast[T,X] (MeventType MeventType, T arg1, X arg2) (at Assets/0.C#/Common/EventCenter.cs:196) SaveDataManager.DeleteFugui01 (System.String site, System.String FuguiName) (at Assets/0.C#/Common/SaveDataManager.cs:517) EventCenter.Broadcast[T,X] (MeventType MeventType, T arg1, X arg2) (at Assets/0.C#/Common/EventCenter.cs:196) FuguiActionTriger.clickToDelete () (at Assets/0.C#/Battle/FuguiActionTriger.cs:519) UnityEngine.Events.InvokableCall.Invoke () (at <c6956609c5d74f5d8e6ed4e5e5f40cc2>:0) UnityEngine.Events.UnityEvent.Invoke () (at <c6956609c5d74f5d8e6ed4e5e5f40cc2>:0) UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272) UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)什么意思
最新发布
05-31

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值