Showing results for 
Show  only  | Search instead for 
Did you mean: Api working like a windows service ?

Occasional Contributor Api working like a windows service ?


Is there any c# documentation to connection mega.exe  , I sending some code to connect mega like an external api but this code block just workin while mega.exe open in my local. We want to run mega from code  



newLib = "Yapi Kredi";
env = new MegaCurrentEnvClass();

root = env.get_GetRoot("");

oFolderLib2 = root.get_GetCollection("Folder of Business Processes");

foreach (MegaObject item3 in oFolderLib2)


hex = item3.get_GetProp("absolute identifier").ToString();

processname = item3.get_GetProp("shortname").ToString();
CreationDate = Convert.ToDateTime(item3.get_GetProp("creation date").ToString());
ModificationDate = Convert.ToDateTime(item3.get_GetProp("modification date").ToString());
coreList.Add(new FolderOfBusiness((int)Enumeration.ObjectType.FolderofBusinessProcesses, processname,

hex, "", "", 1, ReferencedId, ReferencedTypeId, CreationDate, ModificationDate));

RoofId = item3.get_GetProp("absolute identifier").ToString();
RoofTypeId = (int)Enumeration.ObjectType.FolderofBusinessProcesses;



Tags (3)
4 Replies

Re: Api working like a windows service ?

There are 2 entry points to the MEGA API:

- MegaCurrentEnv (the one you are using at the moment) connects to a running instance of MEGA

- Using the MegaDatabase object, you can specify which environment/repository/user to use. In that case Mega must not be running.

Occasional Contributor

Re: Api working like a windows service ?

Hi ,


Thanks for advice , can you show me some code MegaDatabese obeject have wrote with c# .

Which connect  mega and then close mega connection.




Re: Api working like a windows service ?



Here is a short example:


using System;
using System.Collections;
using System.Linq;
using System.Text;
using MegaMapp;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            MegaApplication mapp = new MegaApplication();
            MegaEnvironment myenv = mapp.Environments()["c:\\clients\\XXXXX\\YYYYY"]; //Environment path
            myenv.CurrentAdministrator = "mega"; //User name
            myenv.CurrentPassword = "";             // User password
            foreach(MegaDatabase mydb in myenv.Databases()) {
                if (mydb.Name == "ZZZZZ") { //Repository name
                    MegaRoot myroot = mydb.Open();
                    Console.WriteLine("There are {0} organizational processes.", myroot.get_GetCollection("Organizational process").Count);
                    myroot = null;
            string s = Console.ReadLine();
            myenv = null;
            mapp = null;

Occasional Contributor

Re: Api working like a windows service ?

Hi ,


First of all , thanks for your support .Our Mega.exe in shared folder and our developed api project in my local pc .

When I connect to mega my steps is like that


directory for mega.exe: \\lvdmega\Mega\MEGA 2009 SP5


and login screen at the below.





Then I try your connection code block like at the below .It doesnt connect and error happened.

Error note:MyEnv object is null .



How could we fixed this error and login mega .