用于逐行读取azure blob CSV文件的CSHTML ASP代码
如何逐行加载CSV blob 下面的代码示例将整个blob加载到一个字符串中 最后,我想将CSV blob导入Azure SQL用于逐行读取azure blob CSV文件的CSHTML ASP代码,azure,razor,blobstore,Azure,Razor,Blobstore,如何逐行加载CSV blob 下面的代码示例将整个blob加载到一个字符串中 最后,我想将CSV blob导入Azure SQL { // reference to my blob var blobRef = "thecsvfiles/Test.csv"; // gets the blob as text var astring = WindowsAzureStorage.DownloadBlobAsText(blobRef); Response.Wri
{
// reference to my blob
var blobRef = "thecsvfiles/Test.csv";
// gets the blob as text
var astring = WindowsAzureStorage.DownloadBlobAsText(blobRef);
Response.Write (astring);
}
我只是将整个文件加载到一个字符串中,然后在CR和逗号上拆分
string csvData = WindowsAzureStorage.DownloadBlobAsText("thecsvfiles/DiskSpace.csv");
foreach (string row in csvData.Split('\n').Skip(1))
{
if (!string.IsNullOrEmpty(row))
{
dt.Rows.Add();
int i = 1;
foreach (string cell in row.Split(','))
{
dt.Rows[dt.Rows.Count - 1][i] = cell;
i++;
}
}
}