MongoDB.GridFS/GridFile.cs
/// <summary>
/// Copies one file to another.  The destination file must not exist or an IOException will be thrown.
/// </summary>
/// <exception cref="FileNotFoundException">Source file not found.</exception>
/// <exception cref="IOException">Destination file already exists.</exception>
/// <exception cref="MongoCommandException">A database error occurred executing the copy function.</exception>
Copies one file to another.  The destination file must not exist or an IOException will be thrown.
Copies one file to another . The destination file must not exist or an IOException will be thrown .
public void Copy(String src, String dest){
            if(Exists(src) == false) throw new FileNotFoundException("Not found in the database.", src);
            if(Exists(dest) == true) throw new IOException("Destination file already exists.");
            Document scope = new Document().Append("bucket", this.name).Append("srcfile", src).Append("destfile",dest);
            String func ="function(){\n" +
                            "   var files = db[bucket + \".files\"];\n" +
                            "   var chunks = db[bucket + \".chunks\"];\n" +
                            "   var srcdoc = files.findOne({filename:srcfile});\n" +
                            "   if(srcdoc != undefined){\n" +
                            "       var srcid = srcdoc._id;\n" +
                            "       var newid = ObjectId();\n" +
                            "       srcdoc._id = newid\n" +
                            "       srcdoc.filename = destfile;\n" +
                            "       files.insert(srcdoc);\n" +
                            "       chunks.find({files_id:srcid}).forEach(function(chunk){\n" +
                            "           chunk._id = ObjectId();\n" +
                            "           chunk.files_id = newid;\n" +
                            "           chunks.insert(chunk);\n" +
                            "       });\n" +
                            "       return true;\n" +
                            "   }\n" +
                            "   return false;\n" +
                            "}";
            Document result = db.Eval(func,scope);
        }
public void Copy ( String src , String dest ) { if ( Exists ( src ) == false ) throw new FileNotFoundException ( " " , src ) ; if ( Exists ( dest ) == true ) throw new IOException ( " " ) ; Document scope = new Document ( ) . Append ( " " , this . name ) . Append ( " " , src ) . Append ( " " , dest ) ; String func = " \n " + " \" \" \n " + " \" \" \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " \n " + " " ; Document result = db . Eval ( func , scope ) ; }
Copies one file to another.
Copies one file to another .
//"   print(\"copying \" + srcfile);\n" + //"   return srcdoc; \n" + //"           print(\"copying chunk...\");\n" +
Source file not found.
Source file not found .
Destination file already exists.
Destination file already exists .
A database error occurred executing the copy function.
A database error occurred executing the copy function .
src
String
dest
String