public ActionResult Upload() { // Read settings from the configuration file. var baseAddress = ConfigurationManager.AppSettings["baseAddress"]; String userId = Request.Form["client_id"]; String privateKey = Request.Form["private_key"]; // Create service for uploading file to Groupdocs account var service = new GroupdocsService(baseAddress, userId, privateKey); // Iterate through the uploaded files. Right now we have just one uploaded file at a time. 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. var result = service.UploadFile(file.FileName, String.Empty, file.InputStream, false, String.Empty); // Redirect to Annotation viewer with received GUID. return RedirectToAction("Index", new {guid = result.Guid}); } } // If file was not uploaded redirect to the current page. return RedirectToAction("Index"); }
public JsonResult Poll(String guid) { // Read settings from the configuration file. var baseAddress = ConfigurationManager.AppSettings["baseAddress"]; String userId = Request.Form["client_id"]; String privateKey = Request.Form["private_key"]; var service = new GroupdocsService(baseAddress, userId, privateKey); try { var response = service.ListAnnotations(guid); var output = ""; foreach (AnnotationInfo annotation in response.Annotations) { var replies = ""; foreach (AnnotationReplyInfo reply in annotation.Replies) { replies += reply.UserName + ": " + reply.Message; } output += "Annotation Type: " + annotation.Type + " -- Replies: " + replies + "<br/>"; } return Json(output, JsonRequestBehavior.AllowGet); } catch (Exception) { return Json("Server error or no annotations"); } }
public ActionResult Sample27() { // 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"]; String url = Request.Form["url"]; String name = Request.Form["name"]; String sex = Request.Form["sex"]; String age = Request.Form["age"]; String sunrise = Request.Form["sunrise"]; String resultType = Request.Form["type"]; String fileGuId = ""; var file = Request.Files["file"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("name", name); result.Add("sex", sex); result.Add("age", age); result.Add("sunrise", sunrise); result.Add("type", resultType); String iframe = ""; String message = null; // Check is all needed fields are entered if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample27", 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); //Make request to get document pages as images //if URL to web file was provided - upload the file from Web and get it's GUID if (url != "") { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { //If file uploaded return his GuId fileGuId = guid; } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample27", null, result); } } //if file was uploaded locally - upload the file and get it's GUID if (file.FileName != "") { //Upload local file Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, "uploaded", file.InputStream); if (upload.Guid != null) { //If file uploaded return his guid fileGuId = upload.Guid; } else { //If file wasn't uploaded return error result.Add("error", "Something wrong with entered data"); return View("Sample27", null, result); } } //If user choose file guid if (!fileId.Equals("")) { //Set file guid as entered by user file guid fileGuId = fileId; } System.Collections.Hashtable enteredData = new System.Collections.Hashtable(); enteredData.Add("sex", sex); enteredData.Add("age", age); enteredData.Add("sunrise", sunrise); enteredData.Add("name", name); //Set fileds counter Int32 count = enteredData.Count; //Create Datasource object Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource(); //Create array of DatasourceField objects Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[count]; //Create array od objects with string[] values = new string[1]; //Set DatasourceFiled data Int32 counter = 0; foreach (System.Collections.DictionaryEntry fields in enteredData) { //Set object array content values.SetValue(System.Convert.ToString(fields.Value), 0); Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField(); Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType(); type = 0; field.Name = System.Convert.ToString(fields.Key); field.Type = type; field.Values = values; //Push DatasourceField to array of DatasourceField objects fieldArray.SetValue(field, counter); counter++; } //Set feilds array to the Datasource dataSource.Fields = fieldArray; //Add new Datasource to GroupDocs decimal addDataSource = service.AddDataSource(dataSource); //Check is not empty addDataSource if (!addDataSource.Equals("")) { //If status ok merge Datasource to new pdf file decimal job = service.MergeTemplate(fileGuId, addDataSource, resultType, false); if (!job.Equals("")) { Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult(); //### Check job status for (int n = 0; n <= 5; n++) { //Delay necessary that the inquiry would manage to be processed System.Threading.Thread.Sleep(5000); //Make request to api for get document info by job id jobInfo = service.GetJobDocuments(job); //Check job status, if status is Completed or Archived exit from cycle if (jobInfo.JobStatus.Equals("Completed") || jobInfo.JobStatus.Equals("Archived")) { break; //If job status Postponed throw exception with error } else if (jobInfo.JobStatus.Equals("Postponed")) { result.Add("error", "Job is fail"); return View("Sample27", null, result); } } //Get guid String guid = jobInfo.Inputs[0].Outputs[0].Guid; //Get name String fileName = jobInfo.Inputs[0].Outputs[0].Name; // Definition of folder where to download file String LocalPath = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(LocalPath)) { DirectoryInfo di = Directory.CreateDirectory(LocalPath); } //### Make a request to Storage Api for dowloading file // Download file bool download = service.DownloadFile(guid, LocalPath + fileName); // If file downloaded successful if (download != false) { // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Put file info to the result's list result.Add("message", "File was converted and downloaded to the " + LocalPath + "/" + fileName); result.Add("fileId", guid); // Return to the template return View("Sample27", null, result); } } else { result.Add("error", "MargeTemplate is fail"); return View("Sample27", null, result); } } else { result.Add("error", "AddDataSource returned empty job id"); return View("Sample27", null, result); } return View("Sample27", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample27"); } }
public ActionResult Sample06() { // 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"]; var fiDocument = Request.Files["fi_document"]; var fiSignature = Request.Files["fi_signature"]; String iframe = ""; 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 || Request.Files.Count == 0) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample06", 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); // Upload document for sign to the storage upload = service.UploadFile(fiDocument.FileName, String.Empty, fiDocument.InputStream); // If file uploaded successfuly if (upload.Guid != null) { // Read binary data from InputStream System.IO.BinaryReader reader = new System.IO.BinaryReader(fiSignature.InputStream); // Convert to byte array byte[] bytedata = reader.ReadBytes((Int32)fiSignature.ContentLength); // Convert from byte array to the Base64 string String data = "data:" + fiSignature.ContentType + ";base64," + Convert.ToBase64String(bytedata); //### Create Signer settings object Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo signerSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo(); // Activate signature place signerSettings.PlaceSignatureOn = "1"; signerSettings.Email = "*****@*****.**"; // Set signer name signerSettings.Name = "GroupDocs"; // Transfer signature image signerSettings.Data = data; // Set Heifht for signature signerSettings.Height = new decimal(40d); // Set width for signature signerSettings.Width = new decimal(100d); // Set top coordinate for signature signerSettings.Top = new decimal(0.83319); // Set left coordinate for signature signerSettings.Left = new decimal(0.72171); signerSettings.Fields = new System.Collections.Generic.List<Groupdocs.Api.Contract.Signature.SignatureSignFieldSettingsInfo>().ToArray(); // Make request to sig document Groupdocs.Api.Contract.Signature.SignatureSignDocumentResponse sign = service.SignDocument(upload.Guid, signerSettings); // If document signed if (sign.Status.Equals("Ok")) { System.Threading.Thread.Sleep(5000); Groupdocs.Api.Contract.Signature.SignatureSignDocumentStatusResponse getDocumentStatus = service.GetSignDocumentStatus(sign.Result.JobId); if (getDocumentStatus.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/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + getDocumentStatus.Result.Documents[0].DocumentId; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Put to the result's list received GUID. result.Add("guid", getDocumentStatus.Result.Documents[0].DocumentId); } else { // Redirect to viewer with error. message = getDocumentStatus.ErrorMessage; result.Add("error", message); return View("Sample06", null, result); } } // If request returns error else { // Redirect to viewer with error. message = sign.ErrorMessage; result.Add("error", message); return View("Sample06", null, result); } } } // Redirect to viewer with received result's. return View("Sample06", null, result); } // If data not posted return to template for filling of necessary fields else { return View("Sample06"); } }
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"); } }
public ActionResult Sample43() { // 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"]; String url = Request.Form["url"]; var file = Request.Files["file"]; String guid = ""; String basePath = Request.Form["basePath"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("basePath", basePath); String message = null; String iframe = ""; // 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("Sample43", null, result); } else { if (basePath.Equals("")) { basePath = "https://api.groupdocs.com/v2.0"; } // 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; } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample43", 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; } else { //If file wasn't uploaded return error result.Add("error", "Something wrong with entered data"); return View("Sample43", null, result); } } if (fileId != null) { guid = fileId; } //Create list of file types for converting System.Collections.Generic.List<Groupdocs.Common.FileType> fileType = new System.Collections.Generic.List<Groupdocs.Common.FileType>(); //Add PDF to list of file types fileType.Add(Groupdocs.Common.FileType.Doc); Random rand = new Random(); //Create job which will add line numeration to the document Groupdocs.Api.Contract.CreateJobResult createJob = service.CreateJob(Groupdocs.Common.JobActions.NumberLines | Groupdocs.Common.JobActions.Convert, fileType.ToArray(), false, false, "test" + rand.Next()); if (!createJob.JobGuid.Equals("")) { //Add document to the new job Boolean addJobDocument = service.AddJobDocument(createJob.JobGuid, guid, "", false); if (addJobDocument.Equals(false)) { message = "Add document to job is failed"; result.Add("error", message); return View("Sample43", null, result); } else { //Run job Boolean schedule = service.ScheduleJob(createJob.JobId); System.Threading.Thread.Sleep(5000); //Get documents from job int counter = 5; for (int i = 0; i < counter; i++) { Groupdocs.Api.Contract.GetJobDocumentsResult getDocument = service.GetJobDocuments(createJob.JobId); if (!getDocument.JobStatus.ToString().Equals("Archived")) { System.Threading.Thread.Sleep(5000); } else { guid = getDocument.Inputs[0].Outputs[0].Guid; break; } } if (String.IsNullOrEmpty(guid)) { message = "Get document from job is failed or job is Draft"; result.Add("error", message); return View("Sample43", null, result); } else { // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://realtime-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://realtime-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); result.Add("fileId", guid); return View("Sample43", null, result); } } } else { result.Add("error", "Create job is failed"); return View("Sample43", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample43"); } }
//### callback for Sample41 public ActionResult sample41_callback() { // Get user info String infoFile = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamReader userInfoFile = new System.IO.StreamReader(infoFile); String clientId = userInfoFile.ReadLine(); String privateKey = userInfoFile.ReadLine(); userInfoFile.Close(); // Check is data posted if (Request.HttpMethod == "POST") { //Get callback data from JSON System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); String jsonString = reader.ReadToEnd(); var data = System.Web.Helpers.Json.Decode(jsonString); var serializedData = System.Web.Helpers.Json.Decode(data.SerializedData); String documentGuid = serializedData.DocumentGuid; documentGuid = documentGuid.Replace(" ", ""); String collaboratorGuid = serializedData.UserGuid; collaboratorGuid = collaboratorGuid.Replace(" ", ""); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Make request to api for get document info by job id if (documentGuid != "" && collaboratorGuid != "") { //Get all collaborators for the document Groupdocs.Api.Contract.Annotation.GetCollaboratorsResult getCollaborators = service.GetAnnotationCollaborators(documentGuid); //Create ReviewerInfo array Groupdocs.Api.Contract.ReviewerInfo[] reviewers = new Groupdocs.Api.Contract.ReviewerInfo[getCollaborators.Collaborators.Length]; for (int n = 0; n < getCollaborators.Collaborators.Length; n++) { //Set reviewer rights to view only getCollaborators.Collaborators[n].AccessRights = Groupdocs.Common.AnnotationReviewerRights.CanView; //Add riviewer to ReviewerInfo array reviewers[n] = getCollaborators.Collaborators[n]; } //Make request to API to update reviewer rights Groupdocs.Api.Contract.Annotation.SetReviewerRightsResult setRights = service.SetReviewerRights(documentGuid, reviewers); //path to settings file - temporary save clientId and apiKey like to property file String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt"; //open file in rewrite mode FileStream fcreate = System.IO.File.Open(callbackInfo, FileMode.Create); // will create the file or overwrite it if it already exists //String filePath = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamWriter infoFileStreamWriter = new StreamWriter(fcreate); //w = System.IO.File.CreateText(filePath); infoFileStreamWriter.WriteLine("User rights was set to view only"); //save clientId infoFileStreamWriter.Flush(); infoFileStreamWriter.Close(); } return View("sample41_callback"); } //If data not posted return to template for filling of necessary fields else { return View("sample41_callback"); } }
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 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"); } }
public ActionResult Sample33() { // 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 url1 = Request.Form["url1"]; String url2 = Request.Form["url3"]; String url3 = Request.Form["url3"]; String basePath = Request.Form["basePath"]; String guid = ""; String message = null; String iframe = ""; if (clientId == null || privateKey == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample33", null, result); } else { if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } //Add data to template result.Add("basePath", basePath); result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("url1", url1); result.Add("url2", url2); result.Add("url3", url3); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Create list with URL's System.Collections.Generic.List<String> urlList = new System.Collections.Generic.List<String>(); //Put URL's to list urlList.Add(url1); urlList.Add(url2); urlList.Add(url3); //Create empty list for guid's of uploaded files System.Collections.Generic.List<String> guidsList = new System.Collections.Generic.List<String>(); //Loop for upload document from URL for (int i = 0; i < urlList.Count; i++) { String uploadedGuid = service.UploadUrl(urlList[i]); if (uploadedGuid != null) { //Put uploaded file GUID to list guidsList.Add(uploadedGuid); } else { message = "Upload is failed"; result.Add("error", message); return View("Sample33", null, result); } } //Create list of file types for converting System.Collections.Generic.List<Groupdocs.Common.FileType> fileType = new System.Collections.Generic.List<Groupdocs.Common.FileType>(); //Add PDF to list of file types fileType.Add(Groupdocs.Common.FileType.Pdf); System.Random rand = new System.Random(); //Create job. //First job action is Convert Groupdocs.Api.Contract.CreateJobResult createJob = service.CreateJob(Groupdocs.Common.JobActions.Combine | Groupdocs.Common.JobActions.Convert, fileType.ToArray(), false, false, "test" + rand.Next()); if (!createJob.JobGuid.Equals("")) { //Add uploaded documents to job for (int n = 0; n < guidsList.Count; n++) { Boolean addJobDocument = service.AddJobDocument(createJob.JobGuid, guidsList[n], "", false); if (addJobDocument.Equals(false)) { message = "Add document to job is failed"; result.Add("error", message); return View("Sample33", null, result); } } //Get job for update Groupdocs.Api.Contract.JobInfo jobInfo = new Groupdocs.Api.Contract.JobInfo(); //Update job parameters and action from Convert to Combine jobInfo.EmailResults = true; jobInfo.Status = Groupdocs.Common.JobStatus.Pending; jobInfo.Id = createJob.JobId; jobInfo.Guid = createJob.JobGuid; //Update job Boolean updateJob = service.UpdateJob(jobInfo); if (updateJob.Equals(true)) { System.Threading.Thread.Sleep(5000); //Get documents from job Groupdocs.Api.Contract.GetJobDocumentsResult getDocument = service.GetJobDocuments(createJob.JobGuid); if (String.IsNullOrEmpty(getDocument.Outputs[0].Guid)) { message = "Get document from job is failed or job is Draft"; result.Add("error", message); return View("Sample33", null, result); } else { guid = getDocument.Outputs[0].Guid; // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); result.Add("guid", guid); return View("Sample33", null, result); } } else { message = "Update job is failed"; result.Add("error", message); return View("Sample33", null, result); } } else { message = "Create job is failed"; result.Add("error", message); return View("Sample33", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample33"); } }
public ActionResult Sample32() { // 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 formGuid = Request.Form["formGuid"]; String email = Request.Form["email"]; String templateGuid = Request.Form["templateGuid"]; String basePath = Request.Form["basePath"]; String callbackUrl = Request.Form["callbackUrl"]; String iframe = ""; result.Add("formGuid", formGuid); result.Add("templateGuid", templateGuid); result.Add("clientId", clientId); result.Add("privateKey", privateKey); String message = null; if (clientId == null || privateKey == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample32", 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); // Create text file with user data for callbackUrl handler create_info_file(clientId, privateKey, email); //If user enter form GUID if (!formGuid.Equals("")) { //Post form by it's GUID Groupdocs.Api.Contract.Signature.SignatureStatusResponse postForm = service.PublishForm(formGuid, callbackUrl); //If form posted if (postForm.Status.Equals("Ok")) { message = "Form is published successfully"; result.Add("message", message); //Generate iframe url if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/signature2/forms/signembed/" + formGuid; //iframe to dev server } else if (basePath.Equals("https://dev-api.groupdocs.com/v2.0")) { iframe = "https://dev-apps.groupdocs.com/signature2/forms/signembed/" + formGuid; //iframe to test server } else if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/signature2/forms/signembed/" + formGuid; } else if (basePath.Equals("http://realtime-api.groupdocs.com")) { iframe = "https://relatime-apps.groupdocs.com/signature2/forms/signembed/" + formGuid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); } else { message = postForm.ErrorMessage; result.Add("error", message); } } //If user enter template GUID else { //Create form settings object Groupdocs.Api.Contract.Signature.SignatureFormSettingsInfo formSettings = new Groupdocs.Api.Contract.Signature.SignatureFormSettingsInfo(); //Set notification to true formSettings.NotifyOwnerOnSign = true; //Set form name System.Random rand = new System.Random(); String formName = "test" + rand.Next(0, 1000); //Create form from template Groupdocs.Api.Contract.Signature.SignatureFormResponse createForm = service.CreateForm(templateGuid, "", formName, false, "", "", "", true, false, false, false, false); //If form created if (createForm.Status.Equals("Ok")) { //Publish form Groupdocs.Api.Contract.Signature.SignatureStatusResponse postForm = service.PublishForm(createForm.Result.Form.Id, callbackUrl); if (postForm.Status.Equals("Ok")) { message = "Form is published successfully"; result.Add("message", message); //Generate iframe url if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/signature2/forms/signembed/" + createForm.Result.Form.Id; //iframe to dev server } else if (basePath.Equals("https://dev-api.groupdocs.com/v2.0")) { iframe = "https://dev-apps.groupdocs.com/signature2/forms/signembed/" + createForm.Result.Form.Id; //iframe to test server } else if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/signature2/forms/signembed/" + createForm.Result.Form.Id; } else if (basePath.Equals("http://realtime-api.groupdocs.com")) { iframe = "https://relatime-apps.groupdocs.com/signature2/forms/signembed/" + createForm.Result.Form.Id; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); } else { message = postForm.ErrorMessage; result.Add("error", message); } } else { message = createForm.ErrorMessage; result.Add("error", message); } } return View("Sample32", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample32"); } }
public ActionResult Sample03() { // 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"]; String fileGuid = ""; String iframe = ""; result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("url", url); 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("Sample03", 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 == "") { //### 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) { fileGuid = upload.Guid; // Put uploaded file GuId to the result's list result.Add("guid", upload.Guid); } // If upload was failed return error else { message = "UploadFile returns error"; result.Add("error", message); return View("Sample03", null, result); } } } } else { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { fileGuid = guid; //If file uploaded return his GuId to template result.Add("guid", guid); } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample03", null, result); } } if (!fileGuid.Equals("")) { // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + fileGuid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + fileGuid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + fileGuid; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + fileGuid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); } // Redirect to viewer with received GUID. return View("Sample03", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample03"); } }
public ActionResult Sample31() { // 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 country = Request.Form["country"]; String callbackUrl = Request.Form["callbackUrl"]; String templateGuid = Request.Form["templateGuid"]; String city = Request.Form["city"]; String street = Request.Form["street"]; String guid = ""; String iframe = ""; String basePath = Request.Form["basePath"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("email", email); result.Add("name", name); result.Add("street", street); result.Add("country", country); result.Add("city", city); // 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)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample31", 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 (!templateGuid.Equals("")) { guid = templateGuid; } //Create Hashtable with entere data if (!guid.Equals("")) { System.Collections.Hashtable enteredData = new System.Collections.Hashtable(); enteredData.Add("street", street); enteredData.Add("city", city); enteredData.Add("country", country); enteredData.Add("name", name); enteredData.Add("email", email); //Create Datasource object Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource(); //Create array of DatasourceField objects Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[5]; //Filing DataSource object with user data int index = 0; foreach (System.Collections.DictionaryEntry value in enteredData) { //Create object with value string[] values = new string[1]; values.SetValue(value.Value.ToString(), 0); //Create DataSourceField object Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField(); //Create DataSource Field type Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType(); //Set field type to "text" type = 0; field.Name = value.Key.ToString(); field.Type = type; field.Values = values; //Push DatasourceField to array of DatasourceField objects fieldArray.SetValue(field, index); index = index + 1; } //Set feilds array to the Datasource dataSource.Fields = fieldArray; //Add new Datasource to GroupDocs decimal addDataSource = service.AddDataSource(dataSource); //Check is not empty addDataSource if (!addDataSource.Equals("")) { //If status ok merge Datasource to new pdf file decimal job = service.MergeTemplate(guid, addDataSource, "pdf", false); if (!job.Equals("")) { Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult(); //### Check job status for (int n = 0; n <= 5; n++) { //Delay necessary that the inquiry would manage to be processed System.Threading.Thread.Sleep(5000); //Make request to api for get document info by job id jobInfo = service.GetJobDocuments(job); //Check job status, if status is Completed or Archived exit from cycle if (jobInfo.JobStatus.Equals("Completed") || jobInfo.JobStatus.Equals("Archived")) { break; //If job status Postponed throw exception with error } else if (jobInfo.JobStatus.Equals("Postponed")) { result.Add("error", "Job is fail"); return View("Sample31", null, result); } } //Create envilope using entered by user name Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", name, "", false); if (envelop.Status.Equals("Ok")) { //Add selected document to the envelop 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; } } //Create Field settings object and set field name (which must be unique) Groupdocs.Api.Contract.Signature.SignatureFieldSettingsInfo fieldSettings = new Groupdocs.Api.Contract.Signature.SignatureFieldSettingsInfo(); System.Random rand = new System.Random(); String fieldName = "singlSample" + rand.Next(0, 1000); fieldSettings.Name = fieldName; //Add created field to the Gd account Groupdocs.Api.Contract.Signature.SignatureFieldResponse createField = service.AddSignatureField(fieldSettings); if (createField.Status.Equals("Ok")) { //Add recipient to envelope Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, email, name, "Last", roleId, dec); if (addRecipient.Status.Equals("Ok")) { //Get recipients from envelop Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientsResponse getRecipient = service.GetEnvelopeRecipients(envelop.Result.Envelope.Id); if (getRecipient.Status.Equals("Ok")) { //Get recipient id String recipientId = getRecipient.Result.Recipients[0].Id; //Get documents from envelop Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse getDocuments = service.GetEnvelopeDocuments(envelop.Result.Envelope.Id); if (getDocuments.Status.Equals("Ok")) { //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; //Add created field to the envelop Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, recipientId, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings); if (addField.Status.Equals("Ok")) { //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-api-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("Sample31", null, result); } //If status failed set error for template else { result.Add("error", send.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", addField.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", getDocuments.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", getRecipient.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", addRecipient.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", createField.ErrorMessage); return View("Sample31", null, result); } } else { result.Add("error", addDocument.ErrorMessage); return View("Sample31", null, result); } } //If envelope wasn't created send error else { result.Add("error", envelop.ErrorMessage); return View("Sample31", null, result); } } // If request return's null return error to the template else { result.Add("error", "mergeTemplate is failed"); return View("Sample31", null, result); } } // If request return's null return error to the template else { result.Add("error", "addDataSource is failed"); return View("Sample31", null, result); } } else { result.Add("error", "GUID is empty"); return View("Sample31", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample31"); } }
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 Sample28() { // 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"]; String basePath = Request.Form["basePath"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("fileId", fileId); String error = null; // Check is all needed fields are entered if (clientId == null || privateKey == null || fileId == null) { // If not all fields entered send error message error = "Please enter all parameters"; result.Add("error", error); return View("Sample28", 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); // Get all annotations from document Groupdocs.Api.Contract.Annotation.ListAnnotationsResult annotations = service.ListAnnotations(fileId); // If annotations wasn't found return error if (annotations.Annotations.Length == 0) { error = "File you are entered contains no annotations"; result.Add("error", error); return View("Sample28", null, result); } Groupdocs.Api.Contract.Annotation.DeleteAnnotationResult delAnnot = null; if (annotations.Annotations.Length != 0) { String message = "All annotations deleted successfully"; result.Add("message", message); //Get annotations data for (int i = 0; i < annotations.Annotations.Length; i++) { delAnnot = service.DeleteAnnotation(annotations.Annotations[i].Guid); } } String url = ""; //iframe to prodaction server if (basePath.Equals("https://api.groupdocs.com/v2.0")) { url = "https://apps.groupdocs.com/document-viewer/embed/" + fileId; //iframe to dev server } else if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { url = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + fileId; //iframe to test server } else if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { url = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + fileId; } else if (basePath.Equals("http://realtime-api.groupdocs.com")) { url = "http://realtime-apps.groupdocs.com/document-viewer/embed/" + fileId; } //Set data for template result.Add("url", url); return View("Sample28", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample28"); } }
public ActionResult Sample40() { // 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 formGuid = Request.Form["formGuid"]; String basePath = Request.Form["basePath"]; String callbackUrl = Request.Form["callbackUrl"]; String iframe = ""; result.Add("formGuid", formGuid); result.Add("clientId", clientId); result.Add("privateKey", privateKey); String message = null; if (clientId == null || privateKey == null || formGuid == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample40", null, result); } else { //Set base path if its not entered if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } result.Add("basePath", basePath); // Check if callbackUrl is not empty if (!String.IsNullOrEmpty(callbackUrl)) { result.Add("callbackUrl", callbackUrl); } // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); // Create text file with user data for callbackUrl handler create_info_file(clientId, privateKey, ""); String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt"; //Remove temporary file with callback info if (System.IO.File.Exists(callbackInfo)) { System.IO.File.Delete(callbackInfo); } //Set form name System.Random rand = new System.Random(); String formName = "test" + rand.Next(0, 1000); //Copy form Groupdocs.Api.Contract.Signature.SignatureFormResponse createForm = service.CreateForm("", "", formName, false, "", "", formGuid, true, false, false, false, false); //If form created if (createForm.Status.Equals("Ok")) { //Publish form Groupdocs.Api.Contract.Signature.SignatureStatusResponse postForm = service.PublishForm(createForm.Result.Form.Id, callbackUrl); if (postForm.Status.Equals("Ok")) { message = "Form is published successfully"; result.Add("message", message); //Generate iframe url if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/signature2/forms/signembed/" + createForm.Result.Form.Id; //iframe to dev server } else if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/signature2/forms/signembed/" + createForm.Result.Form.Id; //iframe to test server } else if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/" + createForm.Result.Form.Id; } else if (basePath.Equals("http://realtime-api-groupdocs.dynabic.com")) { iframe = "https://relatime-apps-groupdocs.dynabic.com/signature2/forms/signembed/" + createForm.Result.Form.Id; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); } else { message = postForm.ErrorMessage; result.Add("error", message); } } else { message = createForm.ErrorMessage; result.Add("error", message); } return View("Sample40", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample40"); } }
//### callback check for Sample39 public ActionResult sample40_callback() { // Get user info String infoFile = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamReader userInfoFile = new System.IO.StreamReader(infoFile); String clientId = userInfoFile.ReadLine(); String privateKey = userInfoFile.ReadLine(); userInfoFile.Close(); // Check is data posted if (Request.HttpMethod == "POST") { System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); String jsonString = reader.ReadToEnd(); var data = System.Web.Helpers.Json.Decode(jsonString); var serializedData = System.Web.Helpers.Json.Decode(data.SerializedData); String formGuid = data.SourceId; formGuid = formGuid.Replace(" ", ""); String participantGuid = serializedData.ParticipantGuid; participantGuid = participantGuid.Replace(" ", ""); String jobStatus = data.Eventtype; jobStatus = jobStatus.Replace(" ", ""); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Make request to api for get document info by job id if (jobStatus.Equals("JobCompleted")) { Groupdocs.Api.Contract.Signature.SignatureFormParticipantResponse getDocInfo = service.PublicGetFormParticipant(formGuid, participantGuid); if (getDocInfo.Status.Equals("Ok")) { String guid = getDocInfo.Result.Participant.SignedDocuments[0].DocumentGuid; //path to settings file - temporary save clientId and apiKey like to property file String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt"; //open file in rewrite mode FileStream fcreate = System.IO.File.Open(callbackInfo, FileMode.Create); // will create the file or overwrite it if it already exists //String filePath = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamWriter infoFileStreamWriter = new StreamWriter(fcreate); //w = System.IO.File.CreateText(filePath); infoFileStreamWriter.WriteLine(guid); //save clientId infoFileStreamWriter.Flush(); infoFileStreamWriter.Close(); } } return View("sample40_callback"); } // If data not posted return to template for filling of necessary fields else { return View("sample40_callback"); } }
public ActionResult Sample35() { // 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"]; // 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 (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample35", 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"; } //Make propper URL for basePath if (!basePath.Substring(basePath.Length - 3, 3).Equals("2.0")) { if (!basePath.Substring(basePath.Length - 1, 1).Equals("/")) { basePath = basePath + "/v2.0"; } else { basePath = basePath + "v2.0"; } } result.Add("basePath", basePath); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Check which form is used (if Request.Form["guid"] that meens that this is second form with merge data) if (String.IsNullOrEmpty(Request.Form["guid"])) { //Get data from first form String fileId = Request.Form["guidField"]; String url = Request.Form["url"]; String fileGuId = ""; var file = Request.Files["file"]; //if URL to web file was provided - upload the file from Web and get it's GUID if (url != "") { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { //If file uploaded return his GuId fileGuId = guid; } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample35", null, result); } } //if file was uploaded locally - upload the file and get it's GUID if (file.FileName != "") { //Upload local file Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, "uploaded", file.InputStream); if (upload.Guid != null) { //If file uploaded return his guid fileGuId = upload.Guid; } else { //If file wasn't uploaded return error result.Add("error", "Something wrong with entered data"); return View("Sample35", null, result); } } //If user choose file guid if (!fileId.Equals("")) { //Set file guid as entered by user file guid fileGuId = fileId; } //Get all fields from selected document Groupdocs.Assembly.Contract.TemplateFieldsResult getFields = service.GetTemplateFields(fileGuId); if (getFields.Fields.Length != 0) { //Create support variables and counters String element = ""; Int32 countRadio = 0; Int32 countCheckBox = 0; String fieldName = ""; Groupdocs.Assembly.Data.TemplateField[] fields = getFields.Fields; //Create second form for entering data for merge for (Int32 i = 0; i < fields.Length; i++) { fieldName = fields[i].Name; if (fields[i].Type == "Text") { element += "<br /><label for=\"" + fieldName + "\">" + fields[i].Name + "</label>" + "<br /><input type=\"text\" name=\"" + fieldName + "\" value=\"\" /><br />"; } else if (fields[i].Type == "Checkbox") { element += "<br /><input type=\"checkbox\" name=\"" + fieldName + "\" value=\"" + countCheckBox + "\" >" + fields[i].Name + "</input><br />"; countCheckBox = countCheckBox + 1; } else if (fields[i].Type == "RadioButton") { element += "<br /><input type=\"radio\" name=\"" + fieldName + "\" value=\"" + countRadio + "\" >" + fields[i].Name + "</input><br />"; countRadio = countRadio + 1; } else if (fields[i].Type == "MultiLineText") { element += "<br /><label for=\"" + fieldName + "\">" + fields[i].Name + "</label>" + "<br /><input type=\"textarea\" name=\"" + fieldName + "\" value=\"\" >" + fields[i].Name + "</input><br />"; countCheckBox = countCheckBox + 1; } } result.Add("newForm", element); result.Add("fileId", fileGuId); return View("Sample35", null, result); } else { //If get fields failed result.Add("error", "Something wrong with get fields from template"); return View("Sample35", null, result); } } //If second form with merge data else { //Get file GUID from hidden input String fileGuId = Request.Form["guid"]; string iframe = ""; //Create empty Value collection System.Collections.Specialized.NameValueCollection postData = new System.Collections.Specialized.NameValueCollection(); //Get all POST data postData = Request.Form; //Create empty HashTable System.Collections.Hashtable enteredData = new System.Collections.Hashtable(); //Select data from POST foreach (String elementName in postData) { if (elementName == "clientId") { clientId = postData[elementName]; } else if (elementName == "privateKey") { privateKey = postData[elementName]; } else if (elementName == "basePath") { basePath = postData[elementName]; } else if (elementName == "guid") { fileGuId = postData[elementName]; } else { enteredData.Add(elementName, postData[elementName]); } } //Get all fields from document Groupdocs.Assembly.Contract.TemplateFieldsResult templateFields = service.GetTemplateFields(fileGuId); if (templateFields.Fields.Length != 0) { //Set fileds counter Int32 count = enteredData.Count; //Create Datasource object Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource(); //Create array of DatasourceField objects Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[count]; Int32 counter = 0; //Create DataSourceFieldType object Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType(); //Create counters for RadioButtons and CheckBoxes Int32 counteRadio = -1; Int32 counteCheckBox = -1; //Create DataSourceField for (Int32 n = 0; n < templateFields.Fields.Length; n++) { foreach (System.Collections.DictionaryEntry fields in enteredData) { string[] values = new string[1]; //Check is field name from document equal to field name from merge data if (fields.Key.ToString().Equals(templateFields.Fields[n].Name)) { //Set field type and value if (templateFields.Fields[n].Type.Equals("RadioButton")) { counteRadio = counteRadio + 1; Int32 value; int.TryParse(fields.Value.ToString(), out value); if (counteRadio == value) { values.SetValue(System.Convert.ToString(fields.Value), 0); type = Groupdocs.Assembly.Data.DatasourceFieldType.Text; } else { continue; } } else if (templateFields.Fields[n].Type.Equals("MultiLineText")) { //Set object array content values.SetValue(System.Convert.ToString(fields.Value), 0); type = Groupdocs.Assembly.Data.DatasourceFieldType.Text; } else if (templateFields.Fields[n].Type.Equals("Checkbox")) { counteCheckBox = counteCheckBox + 1; Int32 value; int.TryParse(fields.Value.ToString(), out value); if (counteCheckBox == value) { values.SetValue(System.Convert.ToString("true"), 0); type = Groupdocs.Assembly.Data.DatasourceFieldType.Text; } else { continue; } } else { values.SetValue(System.Convert.ToString(fields.Value), 0); type = Groupdocs.Assembly.Data.DatasourceFieldType.Text; } //Add merge data to field object Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField(); field.Name = System.Convert.ToString(fields.Key); field.Type = type; field.Values = values; //Push DatasourceField to array of DatasourceField objects fieldArray.SetValue(field, counter); counter++; } } } //Set feilds array to the Datasource dataSource.Fields = fieldArray; //Add new Datasource to GroupDocs decimal addDataSource = service.AddDataSource(dataSource); //Check is not empty addDataSource if (!addDataSource.Equals("")) { //If status ok merge Datasource to new pdf file decimal job = service.MergeTemplate(fileGuId, addDataSource, "pdf", false); if (!job.Equals("")) { Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult(); //### Check job status for (int n = 0; n <= 5; n++) { //Delay necessary that the inquiry would manage to be processed System.Threading.Thread.Sleep(5000); //Make request to api for get document info by job id jobInfo = service.GetJobDocuments(job); //Check job status, if status is Completed or Archived exit from cycle if (jobInfo.JobStatus.ToString().Equals("Completed") || jobInfo.JobStatus.ToString().Equals("Archived")) { break; } else if (jobInfo.JobStatus.ToString().Equals("Postponed")) { result.Add("error", "Job is fail"); return View("Sample35", null, result); } } //Get guid String guid = jobInfo.Inputs[0].Outputs[0].Guid; // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Return to the template return View("Sample35", null, result); } else { result.Add("error", "MargeTemplate is fail"); return View("Sample35", null, result); } } else { result.Add("error", "AddDataSource returned empty job id"); return View("Sample35", null, result); } } else { result.Add("error", "Get template fields is failed"); return View("Sample35", null, result); } } } } // If data not posted return to template for filling of necessary fields else { return View("Sample35"); } }
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 Sample36() { // 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 envelopGuid = Request.Form["envelopGuid"]; String basePath = Request.Form["basePath"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("envelopGuid", envelopGuid); String message = null; // Check is all needed fields are entered if (clientId == null || privateKey == null || envelopGuid == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample36", null, result); } else { if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } //Make propper URL for basePath if (!basePath.Substring(basePath.Length - 3, 3).Equals("2.0")) { if (!basePath.Substring(basePath.Length - 1, 1).Equals("/")) { basePath = basePath + "/v2.0"; } else { basePath = basePath + "v2.0"; } } result.Add("basePath", basePath); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; //check if Downloads folder exists and remove it to clean all old files if (Directory.Exists(downloadFolder)) { //Delete Downlaods folder Directory.Delete(downloadFolder, true); //Create empty Downloads folder Directory.CreateDirectory(downloadFolder); } //If Downloads folder not exist create it else { Directory.CreateDirectory(downloadFolder); } //Get documents info from envelop Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse envelopDocuments = service.GetEnvelopeDocuments(envelopGuid); if (envelopDocuments.Status.Equals("Ok")) { //Get document name String documentName = envelopDocuments.Result.Documents[0].Name; //Get signed document from envelop (this method return stream) Stream getSignedDocument = service.GetSignedDocuments(envelopGuid); //Create file from stream if (getSignedDocument.Length > 0) { //Create new file FileStream writeStream = new FileStream(downloadFolder + documentName, FileMode.Create, FileAccess.Write); int Length = 256; //Create byte array with "Length" elements Byte[] buffer = new Byte[Length]; //Read bytes from stream int bytesRead = getSignedDocument.Read(buffer, 0, Length); // write the required bytes while (bytesRead > 0) { //Write stream bytes to file writeStream.Write(buffer, 0, bytesRead); //Read next bytes bytesRead = getSignedDocument.Read(buffer, 0, Length); } //Close stream getSignedDocument.Close(); //Close write stream writeStream.Close(); result.Add("documentName", documentName); message = "Files from the envelope were downloaded to server\'s local folder. You can check it <a href=\"/downloads/" + documentName + "\">here</a>"; result.Add("message", message); } else { result.Add("error", "Get signed document from envelop is failed"); return View("Sample36", null, result); } } else { result.Add("error", envelopDocuments.ErrorMessage); return View("Sample36", null, result); } return View("Sample36", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample36"); } }
public ActionResult Sample42() { // 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"]; String basePath = Request.Form["basePath"]; String guid = ""; String message = null; String iframe = ""; String name = ""; if (clientId == null || privateKey == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample42", null, result); } else { if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } //Add data to template result.Add("basePath", basePath); result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("fileId", fileId); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Create list with URL's Groupdocs.Api.Contract.Annotation.ListAnnotationsResult allAnnotations = service.ListAnnotations(fileId); if (allAnnotations.Annotations.Length != 0) { Random rand = new Random(); //Create job which will get document with annotations Groupdocs.Api.Contract.CreateJobResult createJob = service.CreateJob(Groupdocs.Common.JobActions.ImportAnnotations, null, false, false, "test" + rand.Next()); if (!createJob.JobGuid.Equals("")) { //Add document with annotations to new job Boolean addJobDocument = service.AddJobDocument(createJob.JobGuid, fileId, "pdf", false); if (addJobDocument.Equals(false)) { message = "Add document to job is failed"; result.Add("error", message); return View("Sample42", null, result); } else { //Run job Boolean schedule = service.ScheduleJob(createJob.JobId); System.Threading.Thread.Sleep(5000); //Get documents from job int counter = 5; for (int i = 0; i < counter; i++) { Groupdocs.Api.Contract.GetJobDocumentsResult getDocument = service.GetJobDocuments(createJob.JobId); if (!getDocument.JobStatus.ToString().Equals("Archived")) { System.Threading.Thread.Sleep(5000); } else { guid = getDocument.Inputs[0].Outputs[0].Guid; name = getDocument.Inputs[0].Outputs[0].Name; break; } } if (String.IsNullOrEmpty(guid)) { message = "Get document from job is failed or job is Draft"; result.Add("error", message); return View("Sample42", null, result); } else { // Generate Embed Annotation url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://realtime-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://realtime-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Definition of folder where to download file String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(downloadFolder)) { DirectoryInfo di = Directory.CreateDirectory(downloadFolder); } //### Make a request to Storage Api for dowloading file // Download file bool file = service.DownloadFile(guid, downloadFolder + name); message = "File with annotations was downloaded to server's local folder. You can download it from "; result.Add("message", message); result.Add("name", name); return View("Sample42", null, result); } } } else { message = "Create job is failed"; result.Add("error", message); return View("Sample42", null, result); } } else { message = "Get all anotations is failed"; result.Add("error", message); return View("Sample42", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample42"); } }
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 Sample44() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); string message = null; //Get post data String clientId = Request.Form["clientId"]; String privateKey = Request.Form["privateKey"]; String firstEmail = Request.Form["firstEmail"]; String firstName = Request.Form["firstName"]; String lastName = Request.Form["lastName"]; String secondEmail = Request.Form["secondEmail"]; String basePath = Request.Form["basePath"]; //Set second signer name. Can be obtained in the same manner as first signer name. String secondName = firstName + "2"; String gender = Request.Form["gender"]; var file = Request.Files["file"]; String uploadedGuid = ""; String iframe = ""; String secondIframe = ""; // Check is all requered fields are entered if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(firstEmail) || String.IsNullOrEmpty(secondEmail) || String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(secondName)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample44", null, result); } else { if (basePath.Equals("")) { basePath = "https://api.groupdocs.com/v2.0"; } // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Upload local file Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream); if (upload.Guid != null) { //If file uploaded return it's guid uploadedGuid = upload.Guid; //Check is file uploaded if (!uploadedGuid.Equals("")) { //Created array with data for merging System.Collections.Hashtable enteredData = new System.Collections.Hashtable(); enteredData.Add("gender", gender); enteredData.Add("name", firstName); //Set fields counter Int32 count = enteredData.Count; //Create Datasource object Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource(); //Create array of DatasourceField objects Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[count]; //Set DatasourceFiled data Int32 counter = 0; foreach (System.Collections.DictionaryEntry fields in enteredData) { //Set object array content string[] values = new string[1]; values.SetValue(System.Convert.ToString(fields.Value), 0); Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField(); Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType(); type = 0; field.Name = System.Convert.ToString(fields.Key); field.Type = type; field.Values = values; //Push DatasourceField to array of DatasourceField objects fieldArray.SetValue(field, counter); counter++; } //Set fields array to the Datasource dataSource.Fields = fieldArray; //Add new Datasource to GroupDocs decimal addDataSource = service.AddDataSource(dataSource); //Check is not empty addDataSource if (!addDataSource.Equals("")) { //If status ok merge Datasource to new pdf file decimal job = service.MergeTemplate(uploadedGuid, addDataSource, "pdf", false); if (!job.Equals("")) { //Delay necessary that the inquiry would manage to be processed System.Threading.Thread.Sleep(5000); //Create Job info object Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult(); //Make request to api for get document info by job id jobInfo = service.GetJobDocuments(job); //Get guid String guid = jobInfo.Inputs[0].Outputs[0].Guid; //Get name String fileName = jobInfo.Inputs[0].Outputs[0].Name; //Create envelope Groupdocs.Api.Contract.Signature.SignatureEnvelopeResponse envelop = service.CreateEnvelope("", "", fileName, guid, false); if (envelop.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; } } if (String.IsNullOrEmpty(lastName)) { lastName = "Empty Last Name"; } //Add recipient to envelope Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addFirstRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, firstEmail, firstName, lastName, roleId, dec); if (addFirstRecipient.Status.Equals("Ok")) { //Add second recipient to envelope Groupdocs.Api.Contract.Signature.SignatureEnvelopeRecipientResponse addSecondRecipient = service.AddEnvelopeRecipient(envelop.Result.Envelope.Id, secondEmail, secondName, lastName + "2", roleId, dec); if (addSecondRecipient.Status.Equals("Ok")) { //Get document from envelop 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 = "singlIndex1" + 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.23); envelopFieldSettings.LocationWidth = 150; envelopFieldSettings.LocationHeight = 50; envelopFieldSettings.Name = fieldName; envelopFieldSettings.ForceNewField = true; envelopFieldSettings.Page = 1; //Add envelop field to the document Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addFirstField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addFirstRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings); //Updated field settings for the second signer fieldName = "singlIndex2" + rand.Next(0, 1000); envelopFieldSettings.LocationX = new decimal(0.35); envelopFieldSettings.LocationY = new decimal(0.23); envelopFieldSettings.LocationWidth = 150; envelopFieldSettings.LocationHeight = 50; envelopFieldSettings.Name = fieldName; envelopFieldSettings.ForceNewField = true; envelopFieldSettings.Page = 1; //Add envelop field for the second signer Groupdocs.Api.Contract.Signature.SignatureEnvelopeFieldResponse addSecondField = service.AddEnvelopeField(envelop.Result.Envelope.Id, getDocuments.Result.Documents[0].DocumentId, addSecondRecipient.Result.Recipient.Id, "0545e589fb3e27c9bb7a1f59d0e3fcb9", envelopFieldSettings); //Send envelop Groupdocs.Api.Contract.Signature.SignatureEnvelopeSendResponse send = service.SendEnvelope(envelop.Result.Envelope.Id, String.Empty); //Check envelope send status if (send.Status.Equals("Ok")) { // Generate Embed viewer url with entered file id iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addFirstRecipient.Result.Recipient.Id; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); // Generate Embed viewer url for second signer secondIframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addSecondRecipient.Result.Recipient.Id; secondIframe = Groupdocs.Security.UrlSignature.Sign(secondIframe, privateKey); result.Add("iframe1", iframe); result.Add("iframe2", secondIframe); return View("Sample44", null, result); } //If status failed set error for template else { message = send.ErrorMessage; result.Add("error", message); return View("Sample44", null, result); } } //If get document from envelop is failed return error else { message = getDocuments.ErrorMessage; result.Add("error", message); return View("Sample44", null, result); } } //If add recipient is failed return error else { message = addSecondRecipient.ErrorMessage; result.Add("error", message); return View("Sample44", null, result); } } //If add recipient is failed return error else { message = addFirstRecipient.ErrorMessage; result.Add("error", message); return View("Sample44", null, result); } } //If envelope wasn't created send error else { message = envelop.ErrorMessage; result.Add("error", message); return View("Sample44", null, result); } } else { result.Add("error", "MargeTemplate is fail"); return View("Sample44", null, result); } } else { result.Add("error", "AddDataSource returned empty job id"); return View("Sample44", null, result); } } // If request return's null return error to the template else { message = "Upload is failed"; result.Add("error", message); return View("Sample44", null, result); } } else { //If file wasn't uploaded return error message = "Something wrong with upload"; result.Add("error", message); return View("Sample44", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample44"); } }
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"); } }
//### callback check for Sample21 public ActionResult signature_callback() { // Get user info String infoFile = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamReader userInfoFile = new System.IO.StreamReader(infoFile); String clientId = userInfoFile.ReadLine(); String privateKey = userInfoFile.ReadLine(); userInfoFile.Close(); // Check is data posted if (Request.HttpMethod == "POST") { System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); String jsonString = reader.ReadToEnd(); var data = System.Web.Helpers.Json.Decode(jsonString); String jobId = data.SourceId; jobId = jobId.Replace(" ", ""); String fileId = ""; // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Make request to api for get document info by job id Groupdocs.Api.Contract.GetJobDocumentsResult job = service.GetJobDocuments(jobId); String name = ""; if (job.Inputs[0].Outputs[0].Guid != "") { //Return file guid to the template fileId = job.Inputs[0].Outputs[0].Guid; name = job.Inputs[0].Outputs[0].Name; } // Definition of folder where to download file String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(downloadFolder)) { DirectoryInfo di = Directory.CreateDirectory(downloadFolder); } //### Make a request to Storage Api for dowloading file // Download file bool file = service.DownloadFile(fileId, downloadFolder + name); return View("signature_callback"); } // If data not posted return to template for filling of necessary fields else { String jobId = clientId + ":" + privateKey; return View("signature_callback", null, jobId); } }
//### callback check for Sample37 public ActionResult sample37_callback() { // Get user info String infoFile = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamReader userInfoFile = new System.IO.StreamReader(infoFile); String clientId = userInfoFile.ReadLine(); String privateKey = userInfoFile.ReadLine(); userInfoFile.Close(); // Check is data posted if (Request.HttpMethod == "POST") { System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); String jsonString = reader.ReadToEnd(); var data = System.Web.Helpers.Json.Decode(jsonString); String envelopGuid = data.SourceId; envelopGuid = envelopGuid.Replace(" ", ""); String jobStatus = data.Eventtype; jobStatus = jobStatus.Replace(" ", ""); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Make request to api for get document info by job id if (jobStatus.Equals("JobCompleted")) { String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; //check if Downloads folder exists and remove it to clean all old files if (Directory.Exists(downloadFolder)) { Directory.Delete(downloadFolder, true); Directory.CreateDirectory(downloadFolder); } else { Directory.CreateDirectory(downloadFolder); } Groupdocs.Api.Contract.Signature.SignatureEnvelopeDocumentsResponse envelopDocuments = service.GetEnvelopeDocuments(envelopGuid); if (envelopDocuments.Status.Equals("Ok")) { String documentName = envelopDocuments.Result.Documents[0].Name; Stream getSignedDocument = service.GetSignedDocuments(envelopGuid); if (getSignedDocument.Length > 0) { FileStream writeStream = new FileStream(downloadFolder + documentName, FileMode.Create, FileAccess.Write); int Length = 256; Byte[] buffer = new Byte[Length]; int bytesRead = getSignedDocument.Read(buffer, 0, Length); // write the required bytes while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = getSignedDocument.Read(buffer, 0, Length); } getSignedDocument.Close(); writeStream.Close(); return View("sample37_callback"); } } } return View("sample37_callback"); } // If data not posted return to template for filling of necessary fields else { String jobId = clientId + ":" + privateKey; return View("sample37_callback", null, jobId); } }
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 Sample39() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); string message = null; System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); //Chekck is email entered, if not sign document with widget if (String.IsNullOrEmpty(Request.Form["email"])) { //Get data from ajax System.IO.Stream inputStream = Request.InputStream; System.Text.Encoding encoding = Request.ContentEncoding; System.IO.StreamReader reader = new System.IO.StreamReader(inputStream, encoding); string jsonString = reader.ReadToEnd(); //Parse json data from ajax var postData = Newtonsoft.Json.Linq.JObject.Parse(jsonString); //Get data from parsed object String clientId = postData["userId"].ToString(); String privateKey = postData["privateKey"].ToString(); var document = postData["documents"]; var signers = postData["signers"]; string guid = null; // Check is all needed fields are entered if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey)) { // If not all fields entered send error message message = "Please enter all parameters"; } else { //Create GroupDocs service GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Create document for signing object Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[] documentSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo[1]; documentSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentDocumentSettingsInfo(); documentSettings[0].Name = document[0]["name"].ToString(); documentSettings[0].Data = document[0]["data"].ToString(); //Create signature object Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[] signatureSettings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo[1]; signatureSettings[0] = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSignerSettingsInfo(); signatureSettings[0].Name = signers[0]["name"].ToString(); signatureSettings[0].Data = signers[0]["data"].ToString(); //Create sign settings info object Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo settings = new Groupdocs.Api.Contract.Signature.SignatureSignDocumentSettingsInfo(); settings.Documents = documentSettings; settings.Signers = signatureSettings; //Make request to sign document Groupdocs.Api.Contract.Signature.SignatureSignDocumentResponse sign = service.SignDocument(settings); if (sign.Status.Equals("Ok")) { //Get job GUID string jobGuid = sign.Result.JobId; int counter = 5; //Check signed document status and get signed document GUID for (int i = 0; i < counter; i++) { System.Threading.Thread.Sleep(5000); Groupdocs.Api.Contract.Signature.SignatureSignDocumentStatusResponse getSignDocumentStatus = service.GetSignDocumentStatus(jobGuid); if (getSignDocumentStatus.Status.Equals("Ok")) { if (getSignDocumentStatus.Result.Documents[0].Status.ToString() == "Completed") { guid = getSignDocumentStatus.Result.Documents[0].DocumentId; break; } } else { message = getSignDocumentStatus.ErrorMessage; } } } else { message = sign.ErrorMessage; } } //Add data to responce json result.Add("error", message); result.Add("guid", guid); result.Add("clientId", clientId); result.Add("privateKey", privateKey); //Create json string and return it to ajax request return Json(serializer.Serialize(result)); } //Check if email entered if so sign document with out widget else if (!String.IsNullOrEmpty(Request.Form["email"])) { //Get post data 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"]; var file = Request.Files["file"]; String fileName = ""; String guid = ""; 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); } // 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("Sample39", null, result); } else { //path to settings file - temporary save clientId and apiKey like to property file create_info_file(clientId, privateKey, ""); String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt"; if (System.IO.File.Exists(callbackInfo)) { System.IO.File.Delete(callbackInfo); } // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //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; //Check is file uploaded if (!guid.Equals("") && !fileName.Equals("")) { //Create envelope 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(); 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")) { //Get document from envelop 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; //Add envelop field to the document 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 iframe = "https://apps.groupdocs.com/signature2/signembed/" + envelop.Result.Envelope.Id + "/" + addRecipient.Result.Recipient.Id; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); return View("Sample39", null, result); } //If status failed set error for template else { message = send.ErrorMessage; result.Add("error", message); return View("Sample39", null, result); } } //If get document from envelop is failed return error else { message = getDocuments.ErrorMessage; result.Add("error", message); return View("Sample39", null, result); } } //If add recipient is failed return error else { message = addRecipient.ErrorMessage; result.Add("error", message); return View("Sample39", null, result); } } //If envelope wasn't created send error else { message = envelop.ErrorMessage; result.Add("error", message); return View("Sample39", null, result); } } // If request return's null return error to the template else { message = "Upload is failed"; result.Add("error", message); return View("Sample39", null, result); } } else { //If file wasn't uploaded return error message = "Something wrong with upload"; result.Add("error", message); return View("Sample39", null, result); } } } return View("Sample39"); } // If data not posted return to template for filling of necessary fields else { return View("Sample39"); } }
public ActionResult Sample26() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); String login = Request.Form["login"]; String password = Request.Form["password"]; Groupdocs.Api.Contract.UserInfoResult userInfo = null; String message = null; // Check is all needed fields are entered if (login == null || password == 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("Sample26", 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, "123", "123"); // Get info about user account userInfo = service.LoginUser(login, password); //### Put user info to Hashtable result.Add("FirstName", userInfo.User.FirstName); result.Add("LastName", userInfo.User.LastName); result.Add("NickName", userInfo.User.NickName); result.Add("PrimaryEmail", userInfo.User.PrimaryEmail); result.Add("guid", userInfo.User.Guid); result.Add("pkey", userInfo.User.PrivateKey); // Return Hashtable with results to the template return View("Sample26", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample26"); } }