<configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <!--这里可以定义配置节 --> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> </configSections>
using System.Configuration;
namespace Ninesky.Models.Config
{
/// <summary>
/// 键值元素类
/// <remarks>
/// 创建:2014.03.09
/// </remarks>
/// </summary>
public class KeyValueElement:ConfigurationElement
{
/// <summary>
/// 键
/// </summary>
[ConfigurationProperty("key",IsRequired=true)]
public string Key {
get { return this["key"].ToString(); }
set { this["key"] = value; }
}
/// <summary>
/// 值
/// </summary>
[ConfigurationProperty("value")]
public string Value
{
get { return this["value"].ToString(); }
set { this["value"] = value; }
}
}
}
using System;
using System.Configuration;
namespace Ninesky.Models.Config
{
/// <summary>
/// 元素集合类
/// <remarks>
/// 创建:2014.03.09
/// </remarks>
/// </summary>
[ConfigurationCollection(typeof(KeyValueElement))]
public class KeyValueElementCollection:ConfigurationElementCollection
{
//忽略大小写
public KeyValueElementCollection() : base(StringComparer.OrdinalIgnoreCase) { }
/// <summary>
/// 集合中指定键的元素
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
new public KeyValueElement this[string name]
{
get { return (KeyValueElement)base.BaseGet(name); }
set
{
if (base.Properties.Contains(name)) base[name] = value;
else base.BaseAdd(value);
}
}
/// <summary>
/// 创建新元素.
/// 必须重写
/// </summary>
/// <returns></returns>
protected override ConfigurationElement CreateNewElement()
{
return new KeyValueElement();
}
/// <summary>
/// 获取元素的键
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
protected override object GetElementKey(ConfigurationElement element)
{
return ((KeyValueElement)element).Key;
}
}
}
using System.Configuration;
namespace Ninesky.Models.Config
{
/// <summary>
/// 上传设置配置节
/// <remarks>
/// 创建:2014.03.09
/// </remarks>
/// </summary>
public class UploadConfig:ConfigurationSection
{
private static ConfigurationProperty _property = new ConfigurationProperty(string.Empty, typeof(KeyValueElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
/// <summary>
/// 配置列表
/// </summary>
[ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
private KeyValueElementCollection KeyValues
{
get { return (KeyValueElementCollection)base[_property]; }
set { base[_property] = value; }
}
/// <summary>
/// 最大大小
/// </summary>
public int MaxSize
{
get
{
int _value =0;
if (KeyValues["MaxSize"] != null) int.TryParse(KeyValues["MaxSize"].Value, out _value);
return _value;
}
set
{
if (KeyValues["MaxSize"] == null) KeyValues["MaxSize"] = new KeyValueElement() { Key = "MaxSize", Value = value.ToString() };
else KeyValues["MaxSize"].Value = value.ToString();
}
}
/// <summary>
/// 上传目录
/// 为应用程序目录起的文件夹名,前面不带~/
/// </summary>
public string Path
{
get
{
if (KeyValues["Path"] == null) return "Upload";
return KeyValues["Path"].Value;
}
set
{
if (KeyValues["Path"] == null) KeyValues["Path"] = new KeyValueElement() { Key = "Path", Value = value };
else KeyValues["Path"].Value = value;
}
}
/// <summary>
/// 允许上传的图片类型文件扩展,多个用“,”隔开
/// </summary>
public string ImageExt
{
get
{
if (KeyValues["ImageExt"] == null) return string.Empty;
return KeyValues["ImageExt"].Value;
}
set
{
if (KeyValues["ImageExt"] == null) KeyValues["ImageExt"] = new KeyValueElement() { Key = "ImageExt", Value = value };
else KeyValues["ImageExt"].Value = value;
}
}
/// <summary>
/// 允许上传的Flash类型文件扩展,多个用“,”隔开
/// </summary>
public string FlashExt
{
get
{
if (KeyValues["FlashExt"] == null) return string.Empty;
return KeyValues["FlashExt"].Value;
}
set
{
if (KeyValues["FlashExt"] == null) KeyValues["FlashExt"] = new KeyValueElement() { Key = "FlashExt", Value = value };
else KeyValues["FlashExt"].Value = value;
}
}
/// <summary>
/// 允许上传的媒体类型文件扩展,多个用“,”隔开
/// </summary>
public string MediaExt
{
get
{
if (KeyValues["MediaExt"] == null) return string.Empty;
return KeyValues["MediaExt"].Value;
}
set
{
if (KeyValues["MediaExt"] == null) KeyValues["MediaExt"] = new KeyValueElement() { Key = "MediaExt", Value = value };
else KeyValues["MediaExt"].Value = value;
}
}
/// <summary>
/// 允许上传的文件类型文件扩展,多个用“,”隔开
/// </summary>
public string FileExt
{
get
{
if (KeyValues["FileExt"] == null) return string.Empty;
return KeyValues["FileExt"].Value;
}
set
{
if (KeyValues["FileExt"] == null) KeyValues["FileExt"] = new KeyValueElement() { Key = "FileExt", Value = value };
else KeyValues["FileExt"].Value = value;
}
}
}
}
var _uploadConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~").GetSection("UploadConfig") as Ninesky.Models.Config.UploadConfig;
//文件最大限制
int _maxSize = _uploadConfig.MaxSize;
//文件路径
string _fileParth = _uploadConfig.Path ;
string _dirName;
//允许上传的类型
Hashtable extTable = new Hashtable();
extTable.Add("image", _uploadConfig.ImageExt);
extTable.Add("flash", _uploadConfig.FileExt);
extTable.Add("media", _uploadConfig.MediaExt);
extTable.Add("file", _uploadConfig.FileExt);
var _uploadConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~").GetSection("UploadConfig") as Ninesky.Models.Config.UploadConfig;
//文件最大限制
int _maxSize = _uploadConfig.MaxSize;
_uploadConfig.FileExt = "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2";
_uploadConfig.FlashExt = "swf,flv";
_uploadConfig.ImageExt = "gif,jpg,jpeg,png,bmp";
_uploadConfig.MediaExt = "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb";
_uploadConfig.Path = "Upload";
_uploadConfig.CurrentConfiguration.Save();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有