public ActionResult Sample05()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["srcPath"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String destPath = Request.Form["destPath"];
                String action = Request.Form["copy"];
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("fileId", fileId);
                result.Add("destPath", destPath);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == "" || privateKey == "" || destPath == "")
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample05", null, result);
                }
                else
                {
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    // Create empty variable for file name and id
                    String name = null;
                    decimal id = new decimal();
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            id = upload.Id;
                            name = upload.AdjustedName;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample05", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        id = storageInfo.Files[i].Id;
                                        name = storageInfo.Files[i].Name;
                                    }

                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample05", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample05", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        //Get all files from GroupDocs account
                        Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                        if (storageInfo.Files.Length > 0)
                        {
                            // Get file id and name by entered file GuId
                            for (int i = 0; i < storageInfo.Files.Length; i++)
                            {
                                if (storageInfo.Files[i].Guid == fileId)
                                {
                                    id = storageInfo.Files[i].Id;
                                    name = storageInfo.Files[i].Name;
                                }

                            }
                        }
                        else
                        {
                            message = "Get files list is failed";
                            result.Add("error", message);
                            return View("Sample05", null, result);
                        }
                    }
                    // Check is entered file GuId exists
                    if (name == null || id == 0)
                    {
                        result.Add("error", "File was not found");
                        return View("Sample05", null, result);
                    }
                    // Create path to where copy/move file
                    String path = destPath + "/" + name;
                    Groupdocs.Api.Contract.FileMoveResponse transfer = new Groupdocs.Api.Contract.FileMoveResponse();
                    // Copy file if user choose copy
                    if (action == "Copy")
                    {
                        // Create empty Overide mode
                        Groupdocs.Common.OverrideMode overide = new Groupdocs.Common.OverrideMode();
                        // Make request to the Api to copy file
                        transfer = service.CopyFile(id, path, overide);
                        // Put message to result's list
                        result.Add("button", "Copied");

                    }
                    // If user choose Move file
                    else
                    {
                        Groupdocs.Common.OverrideMode overide = new Groupdocs.Common.OverrideMode();
                        transfer = service.MoveFile(id, path, overide);
                        result.Add("button", "Moved");
                    }
                    // Check is copy/move is successful
                    if (transfer.Status.Equals("Ok"))
                    {
                        // If successful put path to the copy/moved file to the results list
                        result.Add("path", path);
                    }
                    else
                    {
                        // If failed put error message
                        result.Add("error", transfer.ErrorMessage);
                    }

                }
                // Return results to the template
                return View("Sample05", null, result);

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample05");
            }
        }
        public ActionResult Sample07()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                Groupdocs.Api.Contract.ListEntitiesResult files = null;
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample07", null, result);
                }
                else
                {
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //### Get all files and folders from account. Set last argument to True to get thumbnails.
                    files = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                    // If request was successful
                    if (files.Files != null)
                    {
                        // Create empty variables for file name and image tag
                        String name = "";
                        String image = "";
                        // Create tag builders for img and br tag's
                        TagBuilder tagImg = new TagBuilder("img");
                        TagBuilder tagBr = new TagBuilder("br");
                        // Check is file have thumbnail
                        for (int i = 0; i < files.Files.Length; i++)
                        {
                            if (files.Files[i].Thumbnail != null)
                            {
                                // Delete extension from file name
                                int nameLength = files.Files[i].Name.Length;
                                name = files.Files[i].Name.Substring(0, nameLength - 4);
                                // Set local path for thumbnails
                                String LocalPath = AppDomain.CurrentDomain.BaseDirectory + "downloads/" + name + ".jpg";
                                // Convert thumbnail Base64 data to Base64 string
                                String data = Convert.ToBase64String(files.Files[i].Thumbnail);
                                // Convert from Base64 string to byte array
                                byte[] imageBytes = Convert.FromBase64String(data);
                                // Create Memory stream from byte array
                                System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes, 0, imageBytes.Length);
                                // Write memory stream to the file
                                ms.Write(imageBytes, 0, imageBytes.Length);
                                // Create image file from stream
                                System.Drawing.Image img = System.Drawing.Image.FromStream(ms, true);
                                // Save image file
                                img.Save(LocalPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                                img.Dispose();
                                ms.Close();
                                //### Create HTML string with images and names
                                // Set attributes for img tag
                                tagImg.MergeAttribute("src", "/../downloads/" + name + ".jpg", true);
                                tagImg.MergeAttribute("width", "40px");
                                tagImg.MergeAttribute("height", "40px");
                                // Create string from img, file name and br tag
                                image += tagImg.ToString(TagRenderMode.SelfClosing) + files.Files[i].Name + tagBr;
                                name = null;
                            }

                        }
                        // Encode string to HTML string
                        MvcHtmlString images = MvcHtmlString.Create(image);
                        result.Add("images", images);
                        return View("Sample07", null, result);
                    }
                    // If request returns error
                    else
                    {
                        // Redirect to viewer with error.
                        message = "GetFileSystemEntities returns error";
                        result.Add("error", message);
                        return View("Sample07", null, result);
                    }
                }
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample07");
            }
        }
        public ActionResult Sample38()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String email = Request.Form["email"];
                String firstName = Request.Form["firstName"];
                String lastName = Request.Form["lastName"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileGuId = "";
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("email", email);
                result.Add("firstName", firstName);
                result.Add("lastName", lastName);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || email == null || firstName == null || lastName == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample38", null, result);
                }
                else
                {
                    // Create string array with emails
                    String[] collaborators = new String[1];
                    collaborators[0] = email;
                    //Set base path for API if it's not entered by user
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample38", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;
                                    }
                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample38", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample38", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        fileGuId = fileId;
                    }
                    result.Add("fileId", fileGuId);
                    // Generate Embed Annotation url with file GUID
                    string iframe = null;
                    if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://apps.groupdocs.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://realtime-apps.groupdocs.com/document-annotation2/embed/" + fileGuId;
                    }
                    string userGuid = null;
                    //Get all users from GroupDocs account
                    Groupdocs.Api.Contract.GetAccountUsersResult allUsers = service.GetAccountUsers();
                    if (allUsers != null)
                    {
                        //Check is user allready exist in GroupDocs Account
                        for (int i = 0; i < allUsers.Users.Length; i++)
                        {
                            if (email.Equals(allUsers.Users[i].PrimaryEmail))
                            {
                                //If user exist take his GUID
                                userGuid = allUsers.Users[i].Guid;
                                break;
                            }
                        }
                        //If user not exist create him
                        if (userGuid == null)
                        {
                            //Create User info object
                            Groupdocs.Api.Contract.UserInfo user = new Groupdocs.Api.Contract.UserInfo();
                            //Create Role info object
                            Groupdocs.Api.Contract.RoleInfo roleInfo = new Groupdocs.Api.Contract.RoleInfo();
                            //Create array of roles.
                            Groupdocs.Api.Contract.RoleInfo[] roleList = new Groupdocs.Api.Contract.RoleInfo[1];
                            //Set user role Id. Can be: 1 -  SysAdmin, 2 - Admin, 3 - User, 4 - Guest
                            roleInfo.Id = 3;
                            //Set user role name. Can be: SysAdmin, Admin, User, Guest
                            roleInfo.Name = "User";
                            roleList[0] = roleInfo;
                            //Set nick name as entered first name
                            user.NickName = firstName;
                            //Set first name as entered first name
                            user.FirstName = firstName;
                            //Set last name as entered last name
                            user.LastName = lastName;
                            user.Roles = roleList;
                            //Set email as entered email
                            user.PrimaryEmail = email;
                            //Creating of new User user - object with new user info
                            Groupdocs.Api.Contract.UserIdentity newUser = service.UpdateAccountUser(user);

                            // If request return's null return error to the template
                            if (newUser.Guid != null)
                            {
                                //Get GUID of new user
                                userGuid = newUser.Guid;
                            }
                            else
                            {
                                message = "Failed to create new user";
                                result.Add("error", message);
                                return View("Sample38", null, result);
                            }
                        }
                        //Get all collaborators for document
                        Groupdocs.Api.Contract.Annotation.GetCollaboratorsResult getCollaborators = service.GetAnnotationCollaborators(fileGuId);
                        if (getCollaborators != null)
                        {
                            //Check is user allready in collaborators
                            for (int n = 0; n < getCollaborators.Collaborators.Length; n++)
                            {
                                //If user allready in collaborators sign iframe URL with his Client ID
                                if (getCollaborators.Collaborators[n].FirstName.Equals(firstName))
                                {
                                    iframe = iframe + "?uid=" + userGuid;
                                    iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                    break;
                                }
                            }
                            //If user is not in collaborators add him as collaborator
                            if (iframe.Contains("?uid="))
                            {
                                result.Add("iframe", iframe);
                                return View("Sample38", null, result);
                            }
                            else
                            {
                                // Make request to set annotation collaborators
                                Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult collaborate = service.SetAnnotationCollaborators(fileGuId, collaborators);
                                // Check is request return data
                                if (collaborate != null)
                                {
                                    //Sign iframe URL
                                    iframe = iframe + "?uid=" + userGuid;
                                    iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                    // Return primary email to the template
                                    result.Add("collaborator", collaborate.Collaborators[0].PrimaryEmail);
                                    //Return iframe URl to the template
                                    result.Add("iframe", iframe);
                                    return View("Sample38", null, result);
                                }
                                // If request return's null return error to the template
                                else
                                {
                                    message = "Failed to add new collaborator";
                                    result.Add("error", message);
                                    return View("Sample38", null, result);
                                }
                            }
                        }
                        else
                        {
                            message = "Faild to get all collaborators for document";
                            result.Add("error", message);
                            return View("Sample38", null, result);
                        }
                    }
                    else
                    {
                        message = "Faild to get all users from account";
                        result.Add("error", message);
                        return View("Sample38", null, result);
                    }

                }
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample38");
            }
        }
        public ActionResult Sample41()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String[] emailsArray = Request.Form["email[]"].Split(',');
                String[] emails = new String[emailsArray.Length - 1];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String callback = Request.Form["callbackUrl"];
                String fileGuId = "";
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || emails == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample41", null, result);
                }
                else
                {
                    //Add all emails to array
                    if (emailsArray[emailsArray.Length - 1].Equals(""))
                    {
                        for (int n = 0; n < emailsArray.Length - 1; n++)
                        {
                            emails[n] = emailsArray[n];
                        }
                    }
                    else
                    {
                        emails = new String[emailsArray.Length];
                        for (int n = 0; n < emailsArray.Length; n++)
                        {
                            emails[n] = emailsArray[n];
                        }
                    }
                    //path to settings file - temporary save clientId and apiKey like to property file
                    create_info_file(clientId, privateKey, "");
                    //remove temporary file with callback info
                    String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt";
                    if (System.IO.File.Exists(callbackInfo))
                    {
                        System.IO.File.Delete(callbackInfo);
                    }
                    //Set base path for API if it's not entered by user
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;
                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample41", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;
                                    }
                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample41", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample41", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        fileGuId = fileId;
                    }
                    result.Add("fileId", fileGuId);
                    // Generate Embed Annotation url with file GUID
                    string iframe = null;
                    if (callback == null)
                    {
                        callback = "";
                    }
                    result.Add("callbackUrl", callback);
                    //Set file sesion callback - will be trigered when user add, remove or edit commit for annotation
                    Groupdocs.Api.Contract.Annotation.SetSessionCallbackUrlResult setCallback = service.SetSessionCallbackUrl(fileGuId, callback);
                    //Generate iframe URL for iframe
                    if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://apps.groupdocs.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId;
                    }
                    if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://realtime-apps.groupdocs.com/document-annotation2/embed/" + fileGuId;
                    }
                    //Prepare variables
                    string userGuid = null;
                    String email = String.Empty;
                    String[] Email = new String[emails.Length];
                    int counter = 0;
                    //Get all users from account
                    Groupdocs.Api.Contract.GetAccountUsersResult allUsers = service.GetAccountUsers();
                    if (allUsers != null)
                    {
                        //Loop for all users
                        foreach (var item in emails)
                        {
                            //Get current user email
                            email = item;
                            //Add all entered by user emails to emails array to collaborators
                            for (int m = 0; m < emails.Length; m++)
                            {
                                Email[m] = emails[m];
                            }
                            //Loop to get user GUID if user with same email already exist
                            for (int i = 0; i < allUsers.Users.Length; i++)
                            {
                                userGuid = string.Empty;
                                if (email.Equals(allUsers.Users[i].PrimaryEmail))
                                {
                                    userGuid = allUsers.Users[i].Guid;
                                    break;
                                }
                            }
                            //If user not exist create it
                            if (userGuid == null || userGuid == string.Empty)
                            {
                                //Create new user
                                Groupdocs.Api.Contract.UserInfo user = new Groupdocs.Api.Contract.UserInfo();
                                Groupdocs.Api.Contract.RoleInfo roleInfo = new Groupdocs.Api.Contract.RoleInfo();
                                Groupdocs.Api.Contract.RoleInfo[] roleList = new Groupdocs.Api.Contract.RoleInfo[1];
                                roleInfo.Id = 3;
                                roleInfo.Name = "User";
                                roleList[0] = roleInfo;
                                user.FirstName = email;
                                user.LastName = email;
                                user.Roles = roleList;
                                user.PrimaryEmail = email;
                                //Add new user to account
                                Groupdocs.Api.Contract.UserIdentity newUser = service.UpdateAccountUser(user);
                                if (newUser.Guid != null)
                                {
                                    userGuid = newUser.Guid;
                                }
                                else
                                {
                                    message = "Update account user is failed";
                                    result.Add("error", message);
                                    return View("Sample41", null, result);
                                }
                            }
                            System.Threading.Thread.Sleep(2000);
                            //Get all collaborators for selected document
                            Groupdocs.Api.Contract.Annotation.GetCollaboratorsResult getCollaborators = service.GetAnnotationCollaborators(fileGuId);
                            if (getCollaborators != null)
                            {
                                //Check if user already collaborator of the document
                                String urlParameter = null;
                                for (int n = 0; n < getCollaborators.Collaborators.Length; n++)
                                {
                                    //If user is collaborator add his GUID to the URl
                                    if (getCollaborators.Collaborators[n].PrimaryEmail.Equals(email))
                                    {
                                        iframe = iframe + "?uid=" + userGuid;
                                        urlParameter = userGuid;
                                        iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);

                                        break;
                                    }

                                }
                                //If this parameters is null that means that user not a collaborator
                                if (iframe.Contains("?uid=") && urlParameter != null)
                                {
                                    if (counter == 0)
                                    {
                                        counter = 1;
                                        result.Add("iframe", iframe);
                                    }
                                }
                                else
                                {
                                    if (counter == 0)
                                    {
                                        //Add user to collaborators of the document
                                        Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult collaborate = service.SetAnnotationCollaborators(fileGuId, Email);
                                        if (collaborate != null)
                                        {
                                            counter = 1;
                                            iframe = iframe + "?uid=" + userGuid;
                                            iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                            result.Add("iframe", iframe);
                                        }
                                        else
                                        {
                                            result.Add("error", "Set annotation colaborator is failed");
                                            return View("Sample41", null, result);
                                        }
                                    }
                                }

                            }
                            else
                            {
                                result.Add("error", "Get annotation colaborators is failed");
                                return View("Sample41", null, result);
                            }
                        }
                        return View("Sample41", null, result);
                    }
                    else
                    {
                        result.Add("error", "Faild to get all users from account");
                        return View("Sample41", null, result);
                    }
                }
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample41");
            }
        }
        public ActionResult Sample37()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String email = Request.Form["email"];
                String name = Request.Form["name"];
                String lastName = Request.Form["lastName"];
                String callbackUrl = Request.Form["callbackUrl"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileName = "";
                String guid = "";
                String basePath = Request.Form["basePath"];
                String iframe = "";
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("email", email);
                result.Add("firstName", name);
                result.Add("lastName", lastName);
                // Check if callbackUrl is not empty
                if (!String.IsNullOrEmpty(callbackUrl))
                {
                    result.Add("callbackUrl", callbackUrl);
                }
                String message = null;
                // Check is all needed fields are entered
                if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(email)
                    || String.IsNullOrEmpty(lastName) || String.IsNullOrEmpty(name))
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample37", null, result);
                }
                else
                {
                    //path to settings file - temporary save clientId and apiKey like to property file
                    create_info_file(clientId, privateKey, "");
                    if (basePath.Equals(""))
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //if URL to web file was provided - upload the file from Web and get it's GUID
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String uploadWeb = service.UploadUrl(url);
                        if (uploadWeb != null)
                        {
                            //If file uploaded return his GuId
                            guid = uploadWeb;
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileName = storageInfo.Files[i].Name;
                                    }
                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample37", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample37", null, result);
                        }
                    }
                    //if file was uploaded locally - upload the file and get it's GUID
                    if (!file.FileName.Equals(""))
                    {
                        //Upload local file
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        if (upload.Guid != null)
                        {
                            //If file uploaded return his guid
                            guid = upload.Guid;
                            fileName = upload.AdjustedName;
                        }
                        else
                        {
                            //If file wasn't uploaded return error
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample37", null, result);
                        }
                    }
                    if (!fileId.Equals(""))
                    {
                        guid = fileId;
                        //Get all files from GroupDocs account
                        Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                        if (storageInfo.Files.Length > 0)
                        {
                            // Get file id by uploaded file GuId
                            for (int i = 0; i < storageInfo.Files.Length; i++)
                            {
                                if (storageInfo.Files[i].Guid == guid)
                                {
                                    fileName = storageInfo.Files[i].Name;
                                }

                            }
                        }
                        else
                        {
                            message = "Get files list is failed";
                            result.Add("error", message);
                            return View("Sample37", null, result);
                        }

                    }
                    //Check is file uploaded
                    if (!guid.Equals("") && !fileName.Equals(""))
                    {
                        //Create envilope using user id and entered by user name
                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false);
                        if (envelop.Status.Equals("Ok"))
                        {
                            decimal order = new decimal();
                            Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentResponse addDocument = service.AddEnvelopeDocument(envelop.Result.Envelope.Id, guid, order, true);
                            if (addDocument.Status.Equals("Ok"))
                            {
                                decimal dec = new decimal();
                                //Get role list for curent user
                                Groupdocs.Api.Contract.Signature.SignatureRolesResponse roles = service.GetSignatureRoles("");
                                String roleId = "";
                                //Get id of role which can sign
                                for (int i = 0; i < roles.Result.Roles.Length; i++)
                                {
                                    if (roles.Result.Roles[i].Name.Equals("Signer"))
                                    {
                                        roleId = roles.Result.Roles[i].Id;
                                        break;
                                    }
                                }
                                //Add recipient to envelope
                                Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, lastName, roleId, dec);
                                if (addRecipient.Status.Equals("Ok"))
                                {
                                    Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id);
                                    if (getDocuments.Status.Equals("Ok"))
                                    {
                                        System.Random rand = new System.Random();
                                        String fieldName = "singlSample" + rand.Next(0, 1000);
                                        //Create envelop field settings object (LocationsX,Y max value can bee 1.0)
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo envelopFieldSettings = new Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldSettingsInfo();
                                        envelopFieldSettings.LocationX = new decimal(0.15);
                                        envelopFieldSettings.LocationY = new decimal(0.73);
                                        envelopFieldSettings.LocationWidth = 150;
                                        envelopFieldSettings.LocationHeight = 50;
                                        envelopFieldSettings.Name = fieldName;
                                        envelopFieldSettings.ForceNewField = true;
                                        envelopFieldSettings.Page = 1;
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFields = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings);
                                        //Send envelop with callbackUrl url
                                        Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, callbackUrl);
                                        //Check is envelope send status
                                        if (send.Status.Equals("Ok"))
                                        {
                                            // Generate Embed viewer url with entered file id
                                            if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                                            {
                                                iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                                            {
                                                iframe = "https://dev-apps-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                                            {
                                                iframe = "https://stage-apps-groupdocs.dynabic.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                                            {
                                                iframe = "https://realtime-apps.groupdocs.com/signature/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id;
                                            }
                                            iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                                            result.Add("iframe", iframe);
                                            //Set data for template
                                            result.Add("envelop", envelop.Result.Envelope.Id);
                                            result.Add("recipient", addRecipient.Result.Recipient.Id);
                                            return View("Sample37", null, result);
                                        }
                                        //If status failed set error for template
                                        else
                                        {
                                            result.Add("error", send.ErrorMessage);
                                            return View("Sample37", null, result);
                                        }
                                    }
                                    else
                                    {
                                        result.Add("error", getDocuments.ErrorMessage);
                                        return View("Sample37", null, result);
                                    }
                                }
                                else
                                {
                                    result.Add("error", addRecipient.ErrorMessage);
                                    return View("Sample37", null, result);
                                }
                            }
                            else
                            {
                                result.Add("error", addDocument.ErrorMessage);
                                return View("Sample37", null, result);
                            }
                        }
                        //If envelope wasn't created send error
                        else
                        {
                            result.Add("error", envelop.ErrorMessage);
                            return View("Sample37", null, result);
                        }
                    }
                    // If request return's null return error to the template
                    else
                    {
                        result.Add("error", "Upload is failed");
                        return View("Sample37", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample37");
            }
        }
        public ActionResult Sample04()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String fileId = Request.Form["fileId"];
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("fileId", fileId);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || fileId == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample04", null, result);
                }
                else
                {
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //### Get all files and folders from account.
                    Groupdocs.Api.Contract.ListEntitiesResult files = service.GetFileSystemEntities("", 0, -1, null, true, null, null);
                    //Create empty variable for file name
                    String name = null;
                    // Check is files is not null
                    if (files.Files != null)
                    {
                        // Obtaining file name for entered file Id
                        for (int i = 0; i < files.Files.Length; i++)
                        {
                            if (files.Files[i].Guid == fileId)
                            {
                                name = files.Files[i].Name;
                            }

                        }
                    }

                    // Definition of folder where to download file
                    String LocalPath = AppDomain.CurrentDomain.BaseDirectory + "downloads/";
                    //### Make a request to Storage Api for dowloading file
                    // Download file
                    bool file = service.DownloadFile(fileId, LocalPath + name);

                    // If file downloaded successful
                    if (file != false)
                    {
                        // Put file info to the result's list
                        result.Add("path", LocalPath);
                        result.Add("name", name);
                        // Return to the template
                        return View("Sample04", null, result);
                    }
                    // If file download failed
                    else
                    {
                        // Return error to the template
                        message = "DownloadFile returns error";
                        result.Add("error", message);
                        return View("Sample04", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample04");
            }
        }
        public ActionResult Sample02()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                Groupdocs.Api.Contract.ListEntitiesResult files = null;
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    // Transfer error message to template
                    return View("Sample02", null, result);
                }
                else
                {
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Get all files and folders from account.
                    files = service.GetFileSystemEntities("", 0, -1, null, true, null, null);
                    //Check request result
                    if (files.Files != null)
                    {
                        // Create empty variable for results
                        String name = null;
                        // Create TagBuilder for adding HTML tag to the string
                        TagBuilder tag = new TagBuilder("br");

                        // Obtaining all files names
                        for (int i = 0; i < files.Files.Length; i++)
                        {
                            // Creating a string with files names and HTML tag
                            name += files.Files[i].Name + tag;

                        }
                        // Encoding string to the HTML string
                        MvcHtmlString names = MvcHtmlString.Create(name);
                        // Put results to result list
                        result.Add("Names", names);
                        // Transfer result to the template
                        return View("Sample02", null, result);
                    }
                    // If files in request result's is empty return error message
                    else
                    {
                        message = "GetFileSystemEntities returns error";
                        result.Add("error", message);
                        return View("Sample02", null, result);
                    }
                }
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample02");
            }
        }
        public ActionResult Sample30()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String fileName = Request.Form["fileName"];
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("fileName", fileName);
                String fileId = "";
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || fileName == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample30", null, result);
                }
                else
                {
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    Groupdocs.Api.Contract.ListEntitiesResult allFiles = service.GetFileSystemEntities("", 0, -1, null, false, null, null, false);
                    if (allFiles.Files != null)
                    {
                        for (int i = 0; i < allFiles.Files.Length; i++)
                        {
                            if (allFiles.Files[i].Name.Equals(fileName))
                            {
                                fileId = allFiles.Files[i].Guid;
                            }
                        }
                        if (fileId.Equals(""))
                        {
                            message = "This file is no longer available";
                            result.Add("error", message);
                            return View("Sample30", null, result);
                        }
                        else
                        {
                            //### Make a request to Storage Api for deleting file
                            // Delete file
                            bool file = service.DeleteFile(fileId);
                            // If file downloaded successful
                            if (file != false)
                            {
                                // Put fmessage to the result's list
                                result.Add("message", "Done, file deleted from your GroupDocs Storage");
                                // Return to the template
                            }
                            // If file download failed
                            else
                            {
                                // Return error to the template
                                message = "Failed";
                                result.Add("error", message);
                            }
                            return View("Sample30", null, result);
                        }
                    }
                    // If request returns error
                    else
                    {
                        // Redirect to viewer with error.
                        message = "GetFileSystemEntities returns error";
                        result.Add("error", message);

                    }
                    return View("Sample30", null, result);
                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample30");
            }
        }
        public ActionResult Sample16()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileGuId = "";
                String message = null;
                String iframe = "";
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                if (clientId == null || privateKey == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample16", null, result);
                }
                else
                {

                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample16", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;

                                    }

                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample16", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample16", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        fileGuId = fileId;
                    }
                    if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://apps.groupdocs.com/assembly2/questionnaire-assembly/" + fileGuId;
                    }
                    if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://dev-apps-groupdocs.dynabic.com/assembly2/questionnaire-assembly/" + fileGuId;
                    }
                    if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                    {
                        iframe = "https://stage-api-groupdocs.dynabic.com/assembly2/questionnaire-assembly/" + fileGuId;
                    }
                    if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                    {
                        iframe = "https://realtime-apps.groupdocs.com/assembly2/questionnaire-assembly/" + fileGuId;
                    }
                    //Set data for template
                    iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                    result.Add("iframe", iframe);
                    //Set data for template
                    result.Add("guid", fileGuId);
                }
                return View("Sample16", null, result);
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample16");
            }
        }
        public ActionResult Sample17()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String basePath = Request.Form["basePath"];
                String url = Request.Form["url"];
                decimal Id = new decimal();
                String name = "";
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                Groupdocs.Api.Contract.UploadRequestResult upload = null;
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    // Transfer error message to template
                    return View("Sample17", null, result);
                }
                else
                {
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    result.Add("basePath", basePath);
                    if (url.Equals(""))
                    {
                        //### Upload file
                        // Get tag's names from form
                        foreach (string inputTagName in Request.Files)
                        {
                            var file = Request.Files[inputTagName];
                            // Check that file is not fake.
                            if (file.ContentLength > 0)
                            {
                                // Upload file with empty description.
                                upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                                // Check is upload successful
                                if (upload.Guid != null)
                                {
                                    Id = upload.Id;
                                    name = upload.AdjustedName;

                                }
                                // If upload was failed return error
                                else
                                {
                                    message = "UploadFile returns error";
                                    result.Add("error", message);
                                    return View("Sample17", null, result);
                                }
                            }
                        }
                    }
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String uploadUrl = service.UploadUrl(url);
                        if (!uploadUrl.Equals(""))
                        {
                            //Get all files from account
                            Groupdocs.Api.Contract.ListEntitiesResult files = service.GetFileSystemEntities("My Web Documents", 0, -1, null, true, null, null);

                            //Check if request return data
                            if (files.Files.Length != 0)
                            {
                                //Get Name and Id of compresed file
                                for (int i = 0; i < files.Files.Length; i++)
                                {
                                    if (files.Files[i].Guid == uploadUrl)
                                    {
                                        Id = files.Files[i].Id;
                                        name = files.Files[i].Name;
                                    }
                                }

                            }
                            else
                            {
                                //If file GuId is empty return error
                                result.Add("error", "File Name is empty");
                                return View("Sample17", null, result);
                            }
                        }

                    }
                    //Compress uploaded file into "zip" archive
                    decimal convertId = service.CompressFile(Id, Groupdocs.Common.ArchiveType.Zip);
                    //Get all files from account
                    Groupdocs.Api.Contract.ListEntitiesResult filesList = service.GetFileSystemEntities("", 0, -1, null, true, null, null);

                    //Check if request return data
                    if (filesList.Files.Length != 0)
                    {
                        //Get Name and Id of compresed file
                        for (int i = 0; i < filesList.Files.Length; i++)
                        {
                            if (filesList.Files[i].Id == convertId)
                            {
                                name = filesList.Files[i].Name;
                            }
                        }
                        //If file uploaded and compresed return message with file name to the template
                        result.Add("message", "Archive created and saved successfully as " + name);
                        return View("Sample17", null, result);
                    }
                    else
                    {
                        //If file GuId is empty return error
                        result.Add("error", "File Name is empty");

                    }

                }
                return View("Sample17", null, result);
            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample17");
            }
        }
        public ActionResult Sample14()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String path = Request.Form["path"];
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("path", path);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || path == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample14", null, result);
                }
                else
                {
                    //### Create a proper path from entered path
                    //Reaplace dashlet's with proper dashlet "/"
                    String properPath = path.Replace("(\\/)", "/");
                    //Convert string to array
                    String[] pathArray = properPath.Split('/');
                    String lastFolder = "";
                    String newPath = "";
                    //Check if array content more than one element
                    if (pathArray.Length > 1)
                    {
                        //Create string with proper path from array
                        lastFolder = pathArray[pathArray.Length - 1];
                        newPath = String.Join("/", pathArray);
                    }
                    else
                    {
                        lastFolder = pathArray[0];
                    }
                    String basePath = Request.Form["basePath"];
                    //Check is base path entered
                    if (basePath.Equals(""))
                    {
                        //If base path empty set base path to the dev server
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    // Get all folders from account
                    Groupdocs.Api.Contract.ListEntitiesResult folders = service.GetFileSystemEntities("", 0, -1, null, true, null, null);
                    decimal folderId = new decimal();
                    //Get folder Id
                    if (folders.Folders != null)
                    {
                        for (int i = 0; i < folders.Folders.Length; i++)
                        {
                            if (folders.Folders[i].Name == lastFolder)
                            {
                                folderId = folders.Folders[i].Id;
                            }
                        }
                    }
                    //Get all sharers for entered folder
                    Groupdocs.Api.Contract.UserInfo[] shares = service.GetFolderSharers(folderId);
                    // Check is request return data
                    if (shares.Length != 0)
                    {
                        String emails = "";
                        //Get all emails of sharers
                        for (int n = 0; n < shares.Length; n++)
                        {
                            emails += shares[n].PrimaryEmail + "<br />";
                        }
                        //Convert string to HTML string
                        MvcHtmlString email = MvcHtmlString.Create(emails);
                        // Return primary email to the template
                        result.Add("shares", email);
                        return View("Sample14", null, result);
                    }
                    // If request return's null return error to the template
                    else
                    {
                        message = "Something is wrong with your data";
                        result.Add("error", message);
                        return View("Sample14", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample14");
            }
        }
        public ActionResult Sample13()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String email = Request.Form["email"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileGuId = "";
                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);

                result.Add("email", email);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || email == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample13", null, result);
                }
                else
                {
                    // Create string array with emails
                    String[] collaborators = new String[1];
                    collaborators[0] = email;
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample13", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;

                                    }

                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample13", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample13", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        fileGuId = fileId;
                    }
                    // Make request to set annotation collaborators
                    Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult collaborate = service.SetAnnotationCollaborators(fileGuId, collaborators);
                    // Check is request return data
                    if (collaborate != null)
                    {
                        // Return primary email to the template
                        result.Add("collaborator", collaborate.Collaborators[0].PrimaryEmail);
                        result.Add("fileId", fileGuId);
                        return View("Sample13", null, result);
                    }
                    // If request return's null return error to the template
                    else
                    {
                        message = "Something is wrong with your data";
                        result.Add("error", message);
                        return View("Sample13", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample13");
            }
        }
        public ActionResult Sample11()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileGuId = "";
                String annotationType = Request.Form["annotationType"];
                String boxX = Request.Form["boxX"];
                String boxY = Request.Form["boxY"];
                String boxWidth = Request.Form["boxWidth"];
                String boxHeight = Request.Form["boxHeight"];
                String annotationPositionX = Request.Form["annotationPositionX"];
                String annotationPositionY = Request.Form["annotationPositionY"];
                String rangePosition = Request.Form["rangePosition"];
                String rangeLength = Request.Form["rangeLength"];
                String text = Request.Form["text"];
                String iframe = "";

                // Set entered data to the results list
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("fileId", fileId);
                result.Add("type", annotationType);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || annotationType == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample11", null, result);
                }
                else
                {

                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    result.Add("basePath", basePath);
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample11", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;

                                    }

                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample11", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample11", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        //Get all files from GroupDocs account
                        Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                        if (storageInfo.Files.Length > 0)
                        {
                            // Get file id and name by entered file GuId
                            for (int i = 0; i < storageInfo.Files.Length; i++)
                            {
                                if (storageInfo.Files[i].Guid == fileId)
                                {
                                    fileGuId = storageInfo.Files[i].Guid;

                                }

                            }
                        }
                        else
                        {
                            message = "Get files list is failed";
                            result.Add("error", message);
                            return View("Sample11", null, result);
                        }
                    }
                    //###Create AnnotationType
                    Groupdocs.Common.AnnotationType type = new Groupdocs.Common.AnnotationType();
                    //Create Rectangle object
                    Groupdocs.Api.Contract.Rectangle rectangle = new Groupdocs.Api.Contract.Rectangle();
                    //Create Point object
                    Groupdocs.Api.Contract.Data.Point point = new Groupdocs.Api.Contract.Data.Point();
                    //Create Range object
                    Groupdocs.Api.Contract.Range range = new Groupdocs.Api.Contract.Range();
                    //Set annotation parameters if annotation type is point
                    if (annotationType == "point")
                    {
                        type = Groupdocs.Common.AnnotationType.Point;
                        rectangle.X = float.Parse(boxX);
                        rectangle.Y = float.Parse(boxY);
                        rectangle.Width = 0;
                        rectangle.Height = 0;
                        point.X = 0;
                        point.Y = 0;

                    }
                    //Set annotation parameters if annotation type is text
                    else if (annotationType == "text")
                    {
                        type = Groupdocs.Common.AnnotationType.Text;
                        point.X = double.Parse(annotationPositionX);
                        point.Y = double.Parse(annotationPositionY);
                        range.Length = Int32.Parse(rangeLength);
                        range.Position = Int32.Parse(rangePosition);
                    }
                    //Set annotation parameters if annotation type is area
                    else
                    {
                        type = Groupdocs.Common.AnnotationType.Area;
                        point.X = 0;
                        point.Y = 0;
                        rectangle.X = float.Parse(boxX);
                        rectangle.Y = float.Parse(boxY);
                        rectangle.Width = float.Parse(boxWidth);
                        rectangle.Height = float.Parse(boxHeight);
                    }
                    //### Make request to Api to create Annotation
                    Groupdocs.Api.Contract.Annotation.CreateAnnotationResult annotation = service.CreateAnnotation(fileGuId, type, rectangle, point, range, null, null);
                    //Check if GuId of document with added annotation is not empty
                    if (annotation.DocumentGuid != "")
                    {
                        // Generate Embed annotation url with entered file id
                        if (basePath.Equals("https://api.groupdocs.com/v2.0"))
                        {
                            iframe = "https://apps.groupdocs.com/document-annotation2/embed/" + annotation.DocumentGuid;
                        }
                        if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0"))
                        {
                            iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/" + annotation.DocumentGuid;
                        }
                        if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0"))
                        {
                            iframe = "https://stage-api-groupdocs.dynabic.com/document-annotation2/embed/" + annotation.DocumentGuid;
                        }
                        if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0"))
                        {
                            iframe = "https://realtime-apps.groupdocs.com/document-annotation2/embed/" + annotation.DocumentGuid;
                        }
                        //Set data for template
                        iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey);
                        result.Add("iframe", iframe);
                        result.Add("guid", annotation.DocumentGuid);
                        return View("Sample11", null, result);
                    }
                    //If GuId is empty return error
                    else
                    {
                        result.Add("error", "Annotation is fail");
                        return View("Sample11", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample11");
            }
        }
        public ActionResult Sample08()
        {
            // Check is data posted
            if (Request.HttpMethod == "POST")
            {
                //### Set variables and get POST data
                System.Collections.Hashtable result = new System.Collections.Hashtable();
                String clientId = Request.Form["clientId"];
                String privateKey = Request.Form["privateKey"];
                String basePath = Request.Form["basePath"];
                String fileId = Request.Form["fileId"];
                String url = Request.Form["url"];
                var file = Request.Files["file"];
                String fileGuId = "";
                String pageNumber = Request.Form["pageNumber"];
                result.Add("clientId", clientId);
                result.Add("privateKey", privateKey);
                result.Add("pageNumber", pageNumber);
                String message = null;
                // Check is all needed fields are entered
                if (clientId == null || privateKey == null || fileId == null)
                {
                    // If not all fields entered send error message
                    message = "Please enter all parameters";
                    result.Add("error", message);
                    return View("Sample08", null, result);
                }
                else
                {
                    if (basePath == "")
                    {
                        basePath = "https://api.groupdocs.com/v2.0";
                    }
                    // Create service for Groupdocs account
                    GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
                    //Check is chosen local file
                    if (!file.ContentLength.Equals(0))
                    {
                        // Upload file with empty description.
                        Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream);
                        // Check is upload successful
                        if (upload.Guid != null)
                        {
                            // Put uploaded file GuId to the result's list
                            fileGuId = upload.Guid;

                        }
                        // If upload was failed return error
                        else
                        {
                            message = "UploadFile returns error";
                            result.Add("error", message);
                            return View("Sample08", null, result);
                        }

                    }
                    //Check is url entered
                    if (!url.Equals(""))
                    {
                        //Make request to upload file from entered Url
                        String guid = service.UploadUrl(url);
                        if (guid != null)
                        {
                            //Get all files from GroupDocs account
                            Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true);
                            if (storageInfo.Files.Length > 0)
                            {
                                // Get file id by uploaded file GuId
                                for (int i = 0; i < storageInfo.Files.Length; i++)
                                {
                                    if (storageInfo.Files[i].Guid == guid)
                                    {
                                        fileGuId = storageInfo.Files[i].Guid;

                                    }

                                }
                            }
                            else
                            {
                                message = "Get files list is failed";
                                result.Add("error", message);
                                return View("Sample08", null, result);
                            }
                        }
                        //If file wasn't uploaded return error
                        else
                        {
                            result.Add("error", "Something wrong with entered data");
                            return View("Sample08", null, result);
                        }
                    }
                    //Check is file guid entered
                    if (!fileId.Equals(""))
                    {
                        //Get all files from GroupDocs account
                        Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("", 0, -1, null, false, null, null, true);
                        if (storageInfo.Files.Length > 0)
                        {
                            // Get file id and name by entered file GuId
                            for (int i = 0; i < storageInfo.Files.Length; i++)
                            {
                                if (storageInfo.Files[i].Guid == fileId)
                                {
                                    fileGuId = storageInfo.Files[i].Guid;

                                }

                            }
                        }
                        else
                        {
                            message = "Get files list is failed";
                            result.Add("error", message);
                            return View("Sample08", null, result);
                        }
                    }
                    // Make request to get page image url
                    String[] pageUrl = service.GetDocumentPagesImageUrls(fileGuId, "600x750", String.Empty, Int32.Parse(pageNumber), 1, 100, false);
                    // Check if url is not null
                    if (pageUrl != null)
                    {
                        // Redirect to template with receive URL
                        result.Add("url", pageUrl[0]);
                        return View("Sample08", null, result);
                    }
                    // Else return error to the template
                    else
                    {
                        message = "Something is wrong with your data";
                        result.Add("error", message);
                        return View("Sample08", null, result);
                    }

                }

            }
            // If data not posted return to template for filling of necessary fields
            else
            {
                return View("Sample08");
            }
        }
        private void fillTreeView(GroupdocsService service, string path, TreeNodeCollection nodes)
        {
            ListEntitiesResult res = service.GetFileSystemEntities(path, 0, -1, null, true, null, null);

            if (res.Count > 0 && res.Files != null && res.Folders != null)
            {
                //for (int index = 0; index < res.Folders.Length; index++)
                //{
                //    FileSystemFolder folder = res.Folders[index];
                //    TreeNode treeNode = new TreeNode(folder.Name);
                //    treeNode.ImageUrl = "~/DesktopModules/EmbedViewer/images/directory.png";
                //    treeNode.Value = "";
                //    nodes.Add(treeNode);
                //    //fillTreeView(service, path + folder.Name + "/", treeNode.ChildNodes);
                //}
                for (int index = 0; index < res.Files.Length; index++)
                {
                    FileSystemDocument document = res.Files[index];
                    TreeNode treeNode = new TreeNode(document.Name, document.Guid);
                    treeNode.ImageUrl = "~/DesktopModules/EmbedViewer/images/file.png";
                    nodes.Add(treeNode);
                }
            }
        }