从任何函数或app.config文件中读取CSV路径 [英] Read CSV Path From any function or app.config file

查看:103
本文介绍了从任何函数或app.config文件中读取CSV路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[TestClass()]
公共类getMySalesOrderList_UT
{


私有TestContext testContextInstance;
公共字符串路径=";


我在下面的代码中编写了从通用功能读取csv路径的代码
公共无效CSVpath()
{

字符串CSVPath1 =";
Common com1 = new Common();
CSVPath1 = com1.CSVPath();

路径= CSVPath1;

}
公共TestContext TestContext
{

获取
{
返回testContextInstance;
}
设置
{
testContextInstance =值;




}

}


但是在运行代码期间,我在路径"上遇到以下错误:非静态字段,方法或属性需要对象引用.

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
"| DataDirectory | \\ getMySalesOrderList_UT.csv",
"getMySalesOrderList_UT#csv",DataAccessMethod.Sequential),
DeploymentItem("SalesOrder_UT \\" +路径+"\\ getMySalesOrderList_UT.csv"),
TestMethod()]

请帮助我如何从任何函数读取csv路径

[TestClass()]
public class getMySalesOrderList_UT
{


private TestContext testContextInstance;
public string path = "";


i am write below code for read csv path from Common function
public void CSVpath()
{

string CSVPath1="";
Common com1 = new Common();
CSVPath1 = com1.CSVPath();

path = CSVPath1;

}
public TestContext TestContext
{

get
{
return testContextInstance;
}
set
{
testContextInstance = value;




}

}


but during run code i get following error on "path" An object reference is required for the non-static field, method, or property

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
"|DataDirectory|\\getMySalesOrderList_UT.csv",
"getMySalesOrderList_UT#csv", DataAccessMethod.Sequential),
DeploymentItem("SalesOrder_UT\\" + path + "\\getMySalesOrderList_UT.csv"),
TestMethod()]

please help me how to read csv path from any function

推荐答案

使用带有相对路径的Server.MapPath,这应该可以解决您的问题.

有关Server.MapPath的更多信息,请参见: http://msdn.microsoft.com /en-us/library/system.web.httpserverutility.mappath.aspx#Y0 [
use Server.MapPath with relarive path, this should solve your issue.

See more on Server.MapPath : http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx#Y0[^]


这篇关于从任何函数或app.config文件中读取CSV路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆