1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
using System;
using System.Web.Mvc;
using MongoDB.Driver;
using System.Globalization;
using Web.Models;
namespace Web.Controllers
{
public class Datav1Controller : Controller
{
public IMongoDatabase db;
public IMongoCollection<Datav1> Datav1
{
get
{ return db.GetCollection<Datav1>("Datav1"); }
}
public ActionResult Index()
{
//connexion
MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress("localhost", 27017);
MongoClient client = new MongoClient(settings);
this.db = client.GetDatabase("mydatabase");
var collection1 = db.GetCollection<Datav1>("Datav1");
//insertion from file.csv
var root = AppDomain.CurrentDomain.BaseDirectory;
System.IO.StreamReader file = new System.IO.StreamReader(root + @"C:\Users\user PC\Desktop\données.csv");
string fileLines;
while ((fileLines = file.ReadLine()) != null)
{
string[] elements ;
elements = fileLines.Split(new char[] { ' ' });
for (int x = 0; x < elements.Length; x++)
{
var emp = new Datav1();
emp.date= elements[0];
emp.ask = float.Parse(elements[3], CultureInfo.InvariantCulture.NumberFormat);
}
}
return View();
}
}
} |
Partager