예제 #1
0
 /// <summary>
 /// 设置网站信息
 /// </summary>
 /// <param name="name">系统名称</param>
 /// <param name="logo">系统LOGO</param>
 /// <param name="copyright">版权信息</param>
 /// <returns>返回异常信息</returns>
 public static string SetCurrWebInfo(string name, string logo, string copyright)
 {
     try
     {
         string pathFlag      = System.IO.Path.DirectorySeparatorChar.ToString();
         string basePath      = WebHelper.MapPath("/") + pathFlag;
         string webConfigPath = string.Format("{0}Config{1}webConfig.xml", basePath, pathFlag);
         if (!System.IO.File.Exists(webConfigPath)) //文件不存在
         {
             StringBuilder sb = new StringBuilder();
             sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
             sb.Append("<web>");
             sb.AppendFormat("<name>{0}</name>", name);
             sb.AppendFormat("<logo>{0}</logo>", logo);
             sb.AppendFormat("<copyright>{0}</copyright>", copyright);
             sb.Append("</web>");
             System.IO.StreamWriter sw = new System.IO.StreamWriter(webConfigPath, false, Encoding.UTF8);
             sw.Write(sb.ToString());
             sw.Close();
             return(string.Empty);
         }
         XmlHelper.Update(webConfigPath, "/web/name", name);
         XmlHelper.Update(webConfigPath, "/web/logo", logo);
         XmlHelper.Update(webConfigPath, "/web/copyright", copyright);
         return(string.Empty);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
        /// <summary>
        /// 创建一个指定类型带路径的临时文件名
        /// </summary>
        /// <param name="ext">文件类型</param>
        /// <returns></returns>
        private static string CreatTemporaryFileName(string ext, UploadConfig cfg)
        {
            string folder = WebHelper.MapPath(cfg.Folder) + Path.DirectorySeparatorChar.ToString();
            string name   = Guid.NewGuid().ToString("N");

            return(string.Concat(folder, name, ext));
        }
        public static string GetUploadFileUrlPath(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            return(WebHelper.MapPath(url));
        }
예제 #4
0
        /// <summary>
        /// 获取配置文件
        /// </summary>
        /// <param name="configName">配置文件名,带文件扩展名</param>
        /// <returns></returns>
        public static string GetConfigFilePath(string configName)
        {
            string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString();
            string basePath = WebHelper.MapPath("/") + pathFlag;
            string xmlPath  = basePath + string.Format("Config{0}{1}", pathFlag, configName);

            if (!System.IO.File.Exists(xmlPath)) //文件不存在
            {
                return(string.Empty);
            }
            return(xmlPath);
        }
예제 #5
0
        /// <summary>
        /// 获取当前网站系统名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrWebName()
        {
            string pathFlag      = System.IO.Path.DirectorySeparatorChar.ToString();
            string basePath      = WebHelper.MapPath("/") + pathFlag;
            string webConfigPath = string.Format("{0}Config{1}webConfig.xml", basePath, pathFlag);

            if (!System.IO.File.Exists(webConfigPath)) //文件不存在
            {
                return(string.Empty);
            }
            string name = XmlHelper.Read(webConfigPath, "/web/name");

            return(name);
        }
        /// <summary>
        /// 创建一个指定类型带路径的文件名
        /// </summary>
        /// <param name="ext">文件类型</param>
        /// <param name="cfg">上传配置</param>
        /// <param name="customerFileName">自定义文件名</param>
        /// <returns></returns>
        private static string CreateFileName(string ext, UploadConfig cfg, string customerFileName = null)
        {
            string folder = WebHelper.MapPath(cfg.Folder) + Path.DirectorySeparatorChar.ToString();

            folder = string.Concat(folder, DateTime.Now.ToString("yyyyMM", DateTimeFormatInfo.InvariantInfo)) + Path.DirectorySeparatorChar.ToString();
            string name     = customerFileName.ObjToStr().Length > 0 ? customerFileName.ObjToStr() : Guid.NewGuid().ToString("N");
            var    fileName = name.ToUpper().Contains(ext) ? string.Concat(folder, name) : string.Concat(folder, name, ext);

            if (File.Exists(fileName))
            {
                return(CreateFileName(ext, cfg));
            }
            return(fileName.Replace(Globals.GetWebDir(), string.Empty).Replace(Path.DirectorySeparatorChar.ToString(), "/"));
        }
        private static string GetUploadFileDiskPath(string url, UploadConfig cfg)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);

            if (uri.IsAbsoluteUri)
            {
                url = uri.AbsolutePath.Substring(1);
            }
            return(WebHelper.MapPath(url));
        }
        /// <summary>
        /// 获取模块配置xml
        /// </summary>
        /// <returns></returns>
        public static string GetModelConfigXml()
        {
            string pathFlag        = System.IO.Path.DirectorySeparatorChar.ToString();
            string basePath        = WebHelper.MapPath("/") + pathFlag;
            string modelConfigPath = WebConfigHelper.GetAppSettingValue("ModelConfig");

            if (string.IsNullOrEmpty(modelConfigPath))                                 //没有配置实体配置
            {
                modelConfigPath = string.Format("Config{0}modelConfig.xml", pathFlag); //取默认配置
            }
            modelConfigPath = basePath + modelConfigPath;
            if (!System.IO.File.Exists(modelConfigPath)) //文件不存在
            {
                return(string.Empty);
            }
            return(modelConfigPath);
        }
        /// <summary>
        /// 获取上传参数
        /// </summary>
        /// <returns>上传参数</returns>
        public static UploadConfig GetUploadConfig(string configPath, string configName)
        {
            string       path = WebHelper.MapPath(configPath);
            var          doc  = XDocument.Load(path);
            UploadConfig cfg  = new UploadConfig();

            if (doc != null)
            {
                var def = doc.Element("root").Element("default");
                GetConfigByXmlNote(cfg, def);

                var config = doc.Element("root").Element(configName);
                if (config != null)
                {
                    GetConfigByXmlNote(cfg, config);
                }
            }
            return(cfg);
        }
예제 #10
0
 /// <summary>
 /// 获取Web路径
 /// </summary>
 /// <returns></returns>
 public static string GetWebDir()
 {
     return(WebHelper.MapPath("/") + System.IO.Path.DirectorySeparatorChar.ToString());
 }
        /// <summary>
        /// 将缓存目录中的文件保存到实际保存目录,并获取文件信息
        /// </summary>
        /// <param name="attachments">文件信息字符串</param>
        /// <param name="fileSplit">文件分隔符</param>
        /// <param name="itemSplit">文件名和文件路径分隔符</param>
        /// <param name="saveFolder">保存的文件夹</param>
        /// <returns>保存的文件Xml集合</returns>
        public static UploadFileModelCollection SaveAs(string attachments, string configName, string fileSplit, string itemSplit)
        {
            var collection = new UploadFileModelCollection();

            //将缓存中的上传文件另存
            if (!string.IsNullOrWhiteSpace(attachments))
            {
                var files = attachments.Split(new string[] { fileSplit }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var cfg   = GetUploadConfig(configName);

                //如果实际上传文件个数大于配置中限制的个数,则只获取限制个数的文件
                if (cfg.QueueSizeLimit > 0 && files.Count() > cfg.QueueSizeLimit)
                {
                    files = files.Take(cfg.QueueSizeLimit).ToList();
                }

                foreach (var o in files)
                {
                    var items = o.Split(new string[] { itemSplit }, StringSplitOptions.None).ToList();
                    var file  = items[0];
                    var name  = items.Count == 2 ? items[1] : System.IO.Path.GetFileName(file);

                    var tempDiskPath = string.Empty;

                    if (System.IO.Path.IsPathRooted(file))
                    {
                        tempDiskPath = WebHelper.MapPath(file);
                    }
                    else
                    {
                        tempDiskPath = System.IO.Path.Combine(cfg.BasePath, file);
                    }
                    if (System.IO.File.Exists(tempDiskPath))
                    {
                        string folder = WebHelper.MapPath(cfg.Folder);
                        folder = string.Concat(folder, DateTime.Now.ToString("yyyyMM", DateTimeFormatInfo.InvariantInfo));

                        //保存的磁盘目录
                        string diskFolder = string.Empty;

                        if (System.IO.Path.IsPathRooted(folder))
                        {
                            diskFolder = WebHelper.MapPath(folder);
                        }
                        else
                        {
                            diskFolder = System.IO.Path.Combine(cfg.BasePath, folder);
                        }

                        //保存磁盘目录检查
                        if (!System.IO.Directory.Exists(diskFolder))
                        {
                            System.IO.Directory.CreateDirectory(diskFolder);
                        }

                        string fileName    = System.IO.Path.GetFileName(tempDiskPath);
                        string newFilePath = System.IO.Path.Combine(diskFolder, fileName);

                        //将文件移到实际保存路径中
                        System.IO.File.Move(tempDiskPath, newFilePath);

                        var fileInfo = new System.IO.FileInfo(newFilePath);



                        collection.Add(new UploadFileModel()
                        {
                            FileName = name,
                            FilePath = System.IO.Path.Combine(WebHelper.MapPath(folder), fileName),
                            FileSize = fileInfo.Length
                        });
                    }
                }
            }

            return(collection);
        }