C#怎么通过配置文件写路径
2个回答
展开全部
你在Web.config中这样配置即可:
<appSettings>
<add key="ConnectionString" value="server=192.168.19.250;database=hrms_test;uid=pmstest;pwd=pmstest" />
<add key="WebObjectPath" value="http://localhost/LMS/Files/" />
<add key="PhysicsObjectPath" value="E:/Files/"/>
<add key="SystemCode" value="12" />
<add key="OrganizationPath" value ="organization" />
</appSettings>
访问:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LMSWebSite.Common
{
public class SystemParams
{
public static string ConnectionString
{
get { return System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString(); }
}
/// <summary>
/// 组织架构数据库路径
/// </summary>
public static string OrganizationPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["OrganizationPath"].ToString(); }
}
/// <summary>
/// 系统编码
/// </summary>
public static string SystemCode
{
get { return System.Configuration.ConfigurationManager.AppSettings["SystemCode"].ToString(); }
}
/// <summary>
/// 物理上传路径
/// </summary>
public static string PhysicsObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString(); }
}
/// <summary>
/// 虚拟上传路径
/// </summary>
public static string WebObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["WebObjectPath"].ToString(); }
}
}
}
<appSettings>
<add key="ConnectionString" value="server=192.168.19.250;database=hrms_test;uid=pmstest;pwd=pmstest" />
<add key="WebObjectPath" value="http://localhost/LMS/Files/" />
<add key="PhysicsObjectPath" value="E:/Files/"/>
<add key="SystemCode" value="12" />
<add key="OrganizationPath" value ="organization" />
</appSettings>
访问:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LMSWebSite.Common
{
public class SystemParams
{
public static string ConnectionString
{
get { return System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString(); }
}
/// <summary>
/// 组织架构数据库路径
/// </summary>
public static string OrganizationPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["OrganizationPath"].ToString(); }
}
/// <summary>
/// 系统编码
/// </summary>
public static string SystemCode
{
get { return System.Configuration.ConfigurationManager.AppSettings["SystemCode"].ToString(); }
}
/// <summary>
/// 物理上传路径
/// </summary>
public static string PhysicsObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString(); }
}
/// <summary>
/// 虚拟上传路径
/// </summary>
public static string WebObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["WebObjectPath"].ToString(); }
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上正解
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询