Error : while creating a file.
- by Harikrishna
I am storing records of datatable to csv file with the help of the following code :
// we'll use these to check for rows with nulls
var columns = yourTable.Columns
.Cast<DataColumn>();
using (var writer = new StreamWriter(yourPath)) {
for (int i = 0; i < yourTable.Rows.Count; i++) {
DataRow row = yourTable.Rows[i];
// check for any null cells
if (columns.Any(column => row.IsNull(column)))
continue;
string[] textCells = row.ItemArray
.Select(cell => cell.ToString()) // may need to pick a text qualifier here
.ToArray();
// check for non-null but EMPTY cells
if (textCells.Any(text => string.IsNullOrEmpty(text)))
continue;
writer.WriteLine(string.Join(",", textCells));
}
}
But I get the error like
System.UnauthorizedAccessException was unhandled
Message="Access to the path 'D:\\Harikrishna\\Monthly Reports' is denied."
What can be the problem and solution ?