private void PrintFilesInFolder(Folder parentFolder, DocumentService docSvc, double size)
        {
            File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false);
            if (files != null && files.Length > 0)
            {
                foreach (File file in files)
                {
                    if (file.FileSize >= size)
                    {
                        for (int vernum = file.VerNum; vernum >= 1; vernum--)
                        {
                            File verFile = docSvc.GetFileByVersion(file.MasterId, vernum);
                            Console.WriteLine(String.Format("{0,12:0,0}", verFile.FileSize) + " " + parentFolder.FullName + "/" + verFile.Name + " (Version " + vernum.ToString() + ")");
                        }
                    }
                }
            }

            Folder[] folders = docSvc.GetFoldersByParentId(parentFolder.Id, false);
            if (folders != null && folders.Length > 0)
            {
                foreach (Folder folder in folders)
                {
                    PrintFilesInFolder(folder, docSvc, size);
                }
            }
        }
        private void ProcessFilesInFolder(Folder parentFolder, DocumentService docSvc, string rootfolder, Boolean exportdwfs, string property, string propertyvalue, long propid)
        {
            VaultSyncReleased.Document.File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false);
            if (files != null && files.Length > 0)
            {
                foreach (VaultSyncReleased.Document.File file in files)
                {
                    Boolean matchesprop = false;
                    Console.WriteLine("Checking: " + parentFolder.FullName + "/" + file.Name);
                    Document.PropInst[] fileProperties = docSvc.GetProperties(new long[] { file.Id }, new long[] { propid });
                    if (fileProperties[0].Val != null)
                    {
                        //Console.WriteLine(" Property: " + property + " - " + fileProperties[0].Val.ToString());
                        if (fileProperties[0].Val.ToString() == propertyvalue)
                        {
                            matchesprop = true;
                        }
                    }
                    string outputfile = rootfolder + parentFolder.FullName.Substring(1) + "/" + file.Name;
                    outputfile = outputfile.Replace("/", "\\");
                    if (matchesprop)
                    {
                        int vernum = file.VerNum;
                        VaultSyncReleased.Document.File verFile = docSvc.GetFileByVersion(file.MasterId, vernum);
                        for (int counter = 0; counter < outputfile.Length; counter++)
                        {
                            if (outputfile.Substring(counter, 1) == "\\")
                            {
                                try
                                {
                                    System.IO.Directory.CreateDirectory(outputfile.Substring(0, counter));
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.ToString());
                                    Console.WriteLine(outputfile.Substring(0, counter));
                                }
                            }
                        }

                        try
                        {
                            if (System.IO.File.Exists(outputfile))
                            {
                                FileInfo fi = new FileInfo(outputfile);
                                if ((verFile.ModDate == fi.LastWriteTime) && (verFile.FileSize == fi.Length))
                                {
                                    Console.WriteLine("File is uptodate: " + outputfile);
                                }
                                else
                                {
                                    Console.WriteLine("Saving: " + outputfile);
                                    System.IO.File.Delete(outputfile); 
                                    DownloadFileInParts(verFile, docSvc, outputfile);
                                    FileInfo finew = new FileInfo(outputfile);
                                    finew.LastWriteTime = verFile.ModDate;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Saving: " + outputfile);
                                System.IO.File.Delete(outputfile); 
                                DownloadFileInParts(verFile, docSvc, outputfile);
                                FileInfo finew = new FileInfo(outputfile);
                                finew.LastWriteTime = verFile.ModDate;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("ERROR: Saving " + outputfile);
                            Console.WriteLine(ex.Message.ToString());
                        }
                        Console.WriteLine("");
                        //Console.ReadLine();
                    }
                    else
                    {
                        if (System.IO.File.Exists(outputfile))
                        {
                            try
                            {
                                Console.WriteLine("Deleting: " + outputfile);
                                System.IO.File.Delete(outputfile);
                            }
                            catch
                            {
                                Console.WriteLine("ERROR: Deleting " + outputfile);
                            }
                        }
                        Console.WriteLine("");
                    }
                }
            }

            Folder[] folders = docSvc.GetFoldersByParentId(parentFolder.Id, false);
            if (folders != null && folders.Length > 0)
            {
                foreach (Folder folder in folders)
                {
                    ProcessFilesInFolder(folder, docSvc, rootfolder, exportdwfs, property, propertyvalue, propid);
                }
            }
        }
 private void GetFilesInFolder(Folder parentFolder, DocumentService docSvc, string filepath, Int32 fileversion, string checkinfile)
 {
     File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false);
     if (files != null && files.Length > 0)
     {
         foreach (File file in files)
         {
             if (parentFolder.FullName + "/" + file.Name == filepath)
             {
                 for (int vernum = file.VerNum; vernum >= 1; vernum--)
                 {
                     File verFile = docSvc.GetFileByVersion(file.MasterId, vernum);
                     if (vernum == fileversion)
                     {
                         Console.WriteLine(String.Format("{0,12:0,0}", verFile.FileSize) + " " + parentFolder.FullName + "/" + verFile.Name + " (Version " + vernum.ToString() + ")");
                         Console.WriteLine("Writing to " + checkinfile);
                         byte[] bytes;
                         for (int counter = 0; counter < checkinfile.Length; counter++)
                         {
                             if (checkinfile.Substring(counter,1) == "\\")
                             {
                                 try 
                                 {
                                     System.IO.Directory.CreateDirectory(checkinfile.Substring(0,counter));
                                 }
                                 catch (Exception ex)
                                 {
                                     Console.WriteLine(ex.ToString());
                                     Console.WriteLine(checkinfile.Substring(0, counter));
                                 }
                             }
                         }
                         
                         string fileName = docSvc.DownloadFile(verFile.Id, true, out bytes);
                         System.IO.File.WriteAllBytes(checkinfile, bytes);
                     }
                 }
             }
         }
     }
 }
        private void PrintFilesInFolder(Folder parentFolder, DocumentService docSvc, Int32 size, Int32 maxpath)
        {
            Document.File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false);
            if (files != null && files.Length > 0)
            {
                foreach (Document.File file in files)
                {
                    for (int vernum = file.VerNum; vernum >= 1; vernum--)
                    {
                        Document.File verFile = docSvc.GetFileByVersion(file.MasterId, vernum);
                        Int32 filepathlength = parentFolder.FullName.Length + verFile.Name.Length + size;
                        if (filepathlength >= maxpath)
                        {
                            Console.WriteLine(String.Format("{0,4:0,0}", filepathlength) + " chars: " + parentFolder.FullName + "/" + verFile.Name + " (Version " + vernum.ToString() + ")");
                        }
                    } 
                }
            }

            Folder[] folders = docSvc.GetFoldersByParentId(parentFolder.Id, false);
            if (folders != null && folders.Length > 0)
            {
                foreach (Folder folder in folders)
                {
                    PrintFilesInFolder(folder, docSvc, size, maxpath);
                }
            }
        }
        private void ProcessFilesInFolder(Folder parentFolder, DocumentService docSvc, DocumentServiceExtensions docextSrv, string statename, string state, long propid, long prophistid, string checkstates, long newstateid, long newlcdid, string newstate, long revertstateid, string revertstate, string lifecycledefinition)
        {
            string[] states = checkstates.Split('|');
            Autodesk.Connectivity.WebServices.File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false);
            if (files != null && files.Length > 0)
            {
                foreach (Autodesk.Connectivity.WebServices.File file in files)
                {
                    Boolean matchesprop = false;
                    Console.WriteLine("");
                    Console.WriteLine("Checking: " + parentFolder.FullName + "/" + file.Name);
                    Autodesk.Connectivity.WebServices.PropInst[] fileProperties = docSvc.GetProperties(new long[] { file.Id }, new long[] { propid });
                    if (fileProperties[0].Val != null)
                    {
                        //Console.WriteLine(" Property: " + statename + " - " + fileProperties[0].Val.ToString());
                        if (fileProperties[0].Val.ToString() == state)
                        {
                            matchesprop = true;
                        }
                    }
                    //string outputfile = parentFolder.FullName.Substring(1) + "/" + file.Name;
                    //outputfile = outputfile.Replace("/", "\\");
                    if (matchesprop && (file.VerNum > states.Length))
                    {
                        Hashtable users = new Hashtable();
                        for (int vernum = file.VerNum; vernum > file.VerNum - states.Length; vernum--)
                        {
                            //Console.WriteLine(" Property Check: " + vernum.ToString());
                            //Console.WriteLine(" State Check: " + (file.VerNum - vernum).ToString());
                            Console.Write(" Checking State: " + states[file.VerNum - vernum]);
                            Autodesk.Connectivity.WebServices.File verFile = docSvc.GetFileByVersion(file.MasterId, vernum);
                            Autodesk.Connectivity.WebServices.PropInst[] verFileProperties = docSvc.GetProperties(new long[] { verFile.Id }, new long[] { propid });
                            if (verFileProperties[0].Val != null)
                            {
                                //Console.WriteLine(" Property: " + statename + " - " + verFileProperties[0].Val.ToString());
                                //Console.WriteLine(" Property: " + statename + " - " + verFile.CreateUserName);
                                if (fileProperties[0].Val.ToString() == state)
                                {
                                    users.Add(verFileProperties[0].Val.ToString(), verFile.CreateUserName);
                                    Console.Write(" : " + verFile.CreateUserName);
                                }
                            }
                            else
                            {
                                verFileProperties = docSvc.GetProperties(new long[] { verFile.Id }, new long[] { prophistid });
                                if (verFileProperties[0].Val != null)
                                {
                                    //Console.WriteLine(" Property: " + statename + " - " + verFileProperties[0].Val.ToString());
                                    //Console.WriteLine(" Property: " + statename + " - " + verFile.CreateUserName);
                                    if (fileProperties[0].Val.ToString() == state)
                                    {
                                        users.Add(verFileProperties[0].Val.ToString(), verFile.CreateUserName);
                                        Console.Write(" : " + verFile.CreateUserName);
                                    }
                                }
                            }
                            Console.WriteLine("");
                        }
                        Boolean statesmatch = true;
                        List<string> userlist = new List<string>();
                        foreach (string thisstate in states)
                        {
                            //Console.WriteLine("|" + thisstate + "|");
                            //Console.WriteLine("|" + users[thisstate].ToString() + "|");
                            if (!userlist.Contains(users[thisstate].ToString()))
                            {
                                userlist.Add(users[thisstate].ToString());
                            }
                            if (users[thisstate].ToString() == "")
                            {
                                statesmatch = false;
                            }
                        }
                        //Console.WriteLine(users.Count.ToString());
                        //Console.WriteLine(userlist.Count.ToString());
                        if (users.Count != userlist.Count)
                        {
                            statesmatch = false;
                        }
                        //Console.WriteLine(statesmatch.ToString());
                        if (statesmatch)
                        {
                            Console.WriteLine("");
                            Console.WriteLine(" " + parentFolder.FullName + "/" + file.Name);
                            //Console.WriteLine("  Master ID : " + String.Format("{0:0}", file.MasterId));
                            Console.WriteLine("  LifeCycle : " + lifecycledefinition);
                            Console.WriteLine("  State     : " + file.FileLfCyc.LfCycStateName);
                            Console.WriteLine("  New State : " + newstate);
                            try
                            {
                                docextSrv.UpdateFileLifeCycleStates(new long[] { file.MasterId }, new long[] { newstateid }, "Automatic State Change");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("ERROR: Changing state (New State - " + newstate + ")");
                                Console.WriteLine(ex.Message.ToString());
                            }
                            finally
                            {
                            }
                        }
                        else
                        {
                            if (revertstateid == -1)
                            {
                                Console.WriteLine("ERROR: Cannot change state, previous changes not performed by unique users");
                                Console.WriteLine("     : No revert state specified");
                            }
                            else
                            {
                                Console.WriteLine("");
                                Console.WriteLine(" " + parentFolder.FullName + "/" + file.Name);
                                //Console.WriteLine("  Master ID : " + String.Format("{0:0}", file.MasterId));
                                Console.WriteLine("  LifeCycle    : " + lifecycledefinition);
                                Console.WriteLine("  State        : " + file.FileLfCyc.LfCycStateName);
                                Console.WriteLine("  Reverting to : " + revertstate);
                                try
                                {
                                    docextSrv.UpdateFileLifeCycleStates(new long[] { file.MasterId }, new long[] { revertstateid }, "Automatic State Revert");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("ERROR: Changing state (New State - " + revertstate + ")");
                                    Console.WriteLine(ex.Message.ToString());
                                }
                                finally
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("");
                    }
                }
            }

            Folder[] folders = docSvc.GetFoldersByParentId(parentFolder.Id, false);
            if (folders != null && folders.Length > 0)
            {
                foreach (Folder folder in folders)
                {
                    ProcessFilesInFolder(folder, docSvc, docextSrv, statename, state, propid, prophistid, checkstates, newstateid, newlcdid, newstate, revertstateid, revertstate, lifecycledefinition);
                }
            }
        }