Vinoth Kumar

Vinoth Kumar

  • 1.3k
  • 450
  • 32.3k

Could not find a part of the path

Aug 1 2017 2:30 AM
How to solve this error. System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Administrator\Documents\Visual Studio 2010\WebSites\atndreport\Document\Book1.csv'
 
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName.ToString();
string path = Server.MapPath("~/Document/" + filename);
FileUpload1.PostedFile.SaveAs(path);
FetchData(path);
}
}
protected void FetchData(string filepath)
{
DataTable dt = new DataTable();
bool IsFirstRowHeader = true;
string[] columnf = new string[] { "" };
using (TextFieldParser parser = new TextFieldParser(filepath))
{
parser.TrimWhiteSpace = true;
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
if (IsFirstRowHeader)
{
columnf = parser.ReadFields();
foreach (string sds in columnf)
{
DataColumn year = new DataColumn(sds.Trim().ToLower(), Type.GetType("System.String"));
dt.Columns.Add(year);
}
}
while (true)
{
if (IsFirstRowHeader == false)
{
string[] parts = parser.ReadFields();
if (parts == null)
{
break;
}
dt.Rows.Add(parts);
}
IsFirstRowHeader = false;
}
}
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
}
 

Answers (2)