Dear Sir,
I want to read .csv file but it's not working.
please help me sir.
Error:
Server Error in '/aaqms' Application.
URI formats are not supported.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: URI formats are not supported. Source Error:
Line 18: // string filePath = @"D:\AAQMS Data\AQ1.csv";
Line 19: string csvData = " ";
Line 20: using (var stream = File.Open(filePath, FileMode.Open))
Line 21: {
Line 22: using (var reader = new StreamReader(stream))
|
Source File: c:\inetpub\wwwroot\CSV\CSV\WebForm3.aspx.cs Line: 20 Stack Trace:
[ArgumentException: URI formats are not supported.]
System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) +12952291
System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) +110
System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) +22
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +353
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +68
System.IO.File.Open(String path, FileMode mode) +60
CSV.WebForm3.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\CSV\CSV\WebForm3.aspx.cs:20
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
System.Web.UI.Control.OnLoad(EventArgs e) +97
System.Web.UI.Control.LoadRecursive() +61
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
namespace CSV
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string filePath = "file://10.10.4.15/daily hr data/AQ1/AQ1.csv";
// string filePath = @"D:\AAQMS Data\AQ1.csv";
string csvData = " ";
using (var stream = File.Open(filePath, FileMode.Open))
{
using (var reader = new StreamReader(stream))
{
//Read the contents of CSV file.
csvData = reader.ReadToEnd();
}
}
//Create a DataTable.
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Parameters", typeof(string)),
new DataColumn("PM10", typeof(string)),
new DataColumn("PM2.5",typeof(string)),
new DataColumn("SO2", typeof(string)),
new DataColumn("NO", typeof(string)),
new DataColumn("NO2", typeof(string)),
new DataColumn("NOx", typeof(string)),
new DataColumn("CO2", typeof(string)),
new DataColumn("Temp" ,typeof(string)),
new DataColumn("WD", typeof(string)),
new DataColumn("WS", typeof(string)),
new DataColumn("RH",typeof(string)),
new DataColumn("SR", typeof(string)),
new DataColumn("Rain_Gauge",typeof(string)),
new DataColumn(" ",typeof(string)),
new DataColumn(".",typeof(string)),
});
// dt.Rows.Add("UoM", "µg/m3", "µg/m3", "µg/m3", "µg/m3", "µg/m3", "µg/m3", "µg/m3", "degreC", "DEGREE", "m/s", "%", "W/m2", "m m");
//Execute a loop over the rows.
bool firstRow = true;
// foreach (string row in csvData.Split('\n'))
foreach (string row in System.IO.File.ReadAllLines(filePath).Skip(3)) // .Skip(1) is for skipping header
{
if (firstRow)
{
firstRow = false;
}
else
{
if (!string.IsNullOrEmpty(row))
{
int i = 0;
DataRow dr = dt.NewRow();
foreach (string cell in row.Split(';'))
{
dr[i] = cell;
i++;
}
dt.Rows.Add(dr);
}
}
}
//Bind the DataTable.
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}