我要做的是从名为“Attachments”的Windows应用程序文件夹中读取CSV文件中的数据。在Web应用程序中,您可以使用以下方法获取文件夹的路径:
Server.MapPath(@"Attachments/sample.csv");
从Windows应用程序中调用的等效方法是什么?
以下是我的代码。
string[] str = File.ReadAllLines(@"Attachment/sample.csv");
// create new datatable
DataTable dt = new DataTable();
// get the column header means first line
string[] temp = str[0].Split(';');
// creates columns of gridview as per the header name
foreach (string t in temp)
{
dt.Columns.Add(t, typeof(string));
}
Enviornment.SpecialFolder.ProgramFilesX86
:) - Cole Tobin