Ejemplo n.º 1
0
 public ActionResult Sample34()
 {
     // 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 folder = Request.Form["folder"];
         result.Add("clientId", clientId);
         result.Add("privateKey", privateKey);
         String message = null;
         // Check is all needed fields are entered
         if (clientId == null || privateKey == null || folder == null)
         {
             // If not all fields entered send error message
             message = "Please enter all parameters";
             result.Add("error", message);
             return View("Sample34", 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";
             }
             //Remove spaces and tags from entered data
             clientId = System.Text.RegularExpressions.Regex.Replace(clientId.Trim(), @"<(.|\n)*?>", string.Empty);
             privateKey = System.Text.RegularExpressions.Regex.Replace(privateKey.Trim(), @"<(.|\n)*?>", string.Empty);
             basePath = System.Text.RegularExpressions.Regex.Replace(basePath.Trim(), @"<(.|\n)*?>", string.Empty);
             folder = System.Text.RegularExpressions.Regex.Replace(folder.Trim(), @"<(.|\n)*?>", string.Empty);
             result.Add("basePath", basePath);
             //Check path for propper slashes
             if (!folder.LastIndexOf('\\').Equals(-1))
             {
                 folder = folder.Replace("\\", "/");
             }
             // Create service for Groupdocs account
             GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey);
             //### Create folder
             decimal createFodler = service.CreateFolder(folder);
             //Check is returned data is not null
             if (!createFodler.Equals(null))
             {
                 result.Add("folder", folder);
                 return View("Sample34", null, result);
             }
             else
             {
                 // If returned null, return error to the template
                 message = "Something wrong with entered data, folder wasn't created";
                 result.Add("error", message);
                 return View("Sample34", null, result);
             }
         }
     }
     // If data not posted return to template for filling of necessary fields
     else
     {
         return View("Sample34");
     }
 }