Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MongoDb作为C.net的数据源_C#_Mongodb_Mongodb .net Driver - Fatal编程技术网

C# MongoDb作为C.net的数据源

C# MongoDb作为C.net的数据源,c#,mongodb,mongodb-.net-driver,C#,Mongodb,Mongodb .net Driver,嗨,我正试图在datagrid视图中显示我保存在gridfs中的项目,并通过单击它来检索它们,但到目前为止,我在查询mongo时遇到了问题。我不确定它需要什么样的文件类型 var cursor=collection.FindAs 大多数其他示例使用collection.Find。但我没有把Mongo和班级联系起来 这是我的密码,你能帮我让它工作吗 public partial class WebForm1 : System.Web.UI.Page { MongoClien

嗨,我正试图在datagrid视图中显示我保存在gridfs中的项目,并通过单击它来检索它们,但到目前为止,我在查询mongo时遇到了问题。我不确定它需要什么样的文件类型 var cursor=collection.FindAs

大多数其他示例使用collection.Find。但我没有把Mongo和班级联系起来

这是我的密码,你能帮我让它工作吗

    public partial class WebForm1 : System.Web.UI.Page
    {
    MongoClient client;
    MongoServer server;
    MongoDatabase database;
    MongoGridFs gridFs;
    MongoCollection gridCol;


    protected void Page_Load(object sender, EventArgs e)
    {
        client   = new MongoClient();
        server   = client.GetServer();
        database = server.GetDatabase("mydb");
        gridCol = database.GetCollection("fs");
    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
       //gridCol.FindAllAs<CFilez>

           MongoCollection collection = database.GetCollection("fs");
           var searchQuery = Query.EQ("gefunden", "one");
           var cursor = collection.FindAs(
             MongoCursor<CFilez> cursor = collection.FindAllAs<CFilez>();
            cursor.SetLimit(5);

            var list = cursor.ToList();

        GridView1.DataSource = list;
        GridView1.DataBind();
        StatusLabel.Text = "Jive";
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            try
            {
                client = new MongoClient();
                server = client.GetServer();
                database = server.GetDatabase("mydb");

                string filename = FileUpload1.FileName;
                ////File file = File.OpenRead(filename);
                FileUpload1.SaveAs(Server.MapPath("~/Data/") + filename);
                String Fpath = Server.MapPath("~/Data/") + filename;
                ////FileUpload1.SaveAs(Server.MapPath("~/Data/") + filename);
                ////var id = ObjectId.Empty;
                //Stream file = File.OpenRead(Fpath);
                ////gridFs.AddFile(file, filename);
                //gridFs.AddFile(filename);

                using (var fs = new FileStream(Fpath, FileMode.Open))
                {
                    var gridFsInfo = database.GridFS.Upload(fs, filename);
                    var fileId = gridFsInfo.Id;

                }
                StatusLabel.Text = "Upload status: File uploaded!";
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }

我很难理解你的问题到底是什么。你能重新表述一下吗?而且您是否尝试过使用collection=database.GetCollectionfs;游标=集合。查找。。。相反,看看它是否有什么不同?Collection.FindAsqr.ToList