Пример #1
0
 public ActionResult Sample45()
 {
     // 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 folderName = Request.Form["folderName"];
         String fileName = Request.Form["fileName"];
         result.Add("clientId", clientId);
         result.Add("privateKey", privateKey);
         String message = null;
         String table = String.Empty;
         // Check is all needed fields are entered
         if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(fileName))
         {
             //If not all fields entered send error message
             message = "Please enter all parameters";
             result.Add("error", message);
             // Transfer error message to template
             return View("Sample45", 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);
             String path = String.Empty;
             // Generate path for the file
             if (!String.IsNullOrEmpty(folderName))
             {
                 String last = folderName.Substring(folderName.Length - 1, 1);
                 if (last.Equals("/"))
                 {
                     path = folderName + fileName;
                 } else {
                     path = folderName + "/" + fileName;
                 }
             } else {
                 path = fileName;
             }
             //Get all info for the document
             Groupdocs.Api.Contract.Documents.GetDocumentInfoResult documentInfo = service.GetDocumentMetadata(path);
             if (documentInfo != null)
             {
                 //###Create table with changes for template
                 table = "<table class='border'>";
                 table += "<tr><td><font color='green'>Parameter</font></td><td><font color='green'>Info</font></td></tr>";
                 // Get type of responce object
                 Type res_type = documentInfo.GetType();
                 // Create dictionary for propertyes
                 System.Reflection.PropertyInfo[] properties = res_type.GetProperties();
                 // Convert responce object to dictionary
                 System.Collections.Generic.Dictionary<String, object> output = new System.Collections.Generic.Dictionary<string, object>(properties.Count());
                 //Add each property to the dictionary
                 foreach (System.Reflection.PropertyInfo property in properties)
                 {
                     output.Add(property.Name, property.GetValue(documentInfo, null));
                 }
                 // Get Keys and Values from the dictionary and write them to the result table
                 foreach(System.Collections.Generic.KeyValuePair<string, object> data in output)
                 {
                     if (!data.Value.GetType().Name.Equals("DocumentViewInfo"))
                     {
                         table += "<tr><td>" + data.Key + "</td><td>" + data.Value + "</td></tr>";
                     }
                 }
                 table += "<tr><td>Name</td><td>" + documentInfo.LastView.Document.Name + "</td></tr>";
                 table += "<tr><td>Type</td><td>" + documentInfo.LastView.Document.Type + "</td></tr>";
                 table += "<tr><td>Size</td><td>" + documentInfo.LastView.Document.Size + "</td></tr>";
                 table += "<tr><td>URL</td><td>" + documentInfo.LastView.Document.Url + "</td></tr>";
                 table += "<tr><td>Path</td><td>" + documentInfo.LastView.Document.DocumentPath + "</td></tr>";
                 table += "</table>";
                 //Convert string to HTML string
                 MvcHtmlString infoTable = MvcHtmlString.Create(table);
                 result.Add("result", infoTable);
             }
             // Return Hashtable with results to the template
             return View("Sample45", null, result);
         }
     }
     // If data not posted return to template for filling of necessary fields
     else
     {
         return View("Sample45");
     }
 }