TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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();
}
}
Reply
Answers (
2
)
Bulk Email Response
Send Email with localhost IIS SSL