hi i need to read excel file which is stored in s3 server,i tried but it is showing invalid internet address.please help me to solve
string fullPath = "http://tempfordevelopment.s3.amazonaws.com/ad53498f-74e8-412c-8c8f-e36b18f16e4eEmailExcel2.xlsx";
//Uri uri = new Uri(fullPath);
//string excelLocation = uri.LocalPath;
String sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fullPath + "; Extended Properties='Excel 8.0;HDR=Yes'";
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
OleDbConnection objConn = new OleDbConnection(sConnectionString);
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", sConnectionString);
MyCommand.TableMappings.Add("Table", "Net-informations.com");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);/////Here i am getting error as invalid internet address
DataTable table = DtSet.Tables[0];
string[] strings = new string[table.Rows.Count];
int idx = 0;
foreach (DataRow row in table.Rows)
{
StringBuilder sb = new StringBuilder();
object[] cells = row.ItemArray;
for (int i = 0; i < cells.Length; i++)
{
if (i != 0) sb.Append(',');
sb.Append(cells[i]);
}
strings[idx++] = sb.ToString();
}
You can’t directly open files over the http. You’ll have to download it and then open it from disk. The easiest way for you to download it is probably going to be with WebClient.
Something like this should work if you don’t want to keep the file on disk: