/// <summary>
        /// Shows how to get protection type
        /// </summary>
        /// <param name="inputFileName">input file name with complete path.</param>
        private static void GetProtectionType(string inputFileName)
        {
            // ExStart:GetProtectionType
            Document       doc            = new Document(inputFileName);
            ProtectionType protectionType = doc.ProtectionType;

            // ExEnd:GetProtectionType
            Console.WriteLine("\nDocument protection type is " + protectionType.ToString());
        }
Exemple #2
0
        /***********Method  ChangeProtection Added by:Zeeshan*******/
        public bool ChangeProtection(string oldPassword, string newPassword, ProtectionType protectionType)
        {
            try
            {
                //check whether file is set or not
                if (FileName == "")
                {
                    throw new Exception("No file name specified");
                }

                //build URI
                string strURI = Product.BaseProductUri + "/words/" + FileName;
                strURI += "/protection";

                //sign URI
                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                ProtectionRequest protectionRequest = new ProtectionRequest();
                protectionRequest.Password       = oldPassword;
                protectionRequest.NewPassword    = newPassword;
                protectionRequest.ProtectionType = protectionType.ToString();

                string strJSON = JsonConvert.SerializeObject(protectionRequest);

                Stream       responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);
                StreamReader reader         = new StreamReader(responseStream);

                //further process JSON response
                string strResponseJSON = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject parsedJSON = JObject.Parse(strResponseJSON);

                //Deserializes the JSON to a object.
                BaseResponse baseResponse = JsonConvert.DeserializeObject <BaseResponse>(parsedJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        /***********Method  ProtectDocument Added by:Zeeshan*******/
        public bool ProtectDocument(string password, ProtectionType protectionType)
        {
            try
            {
                //check whether file is set or not
                if (FileName == "")
                    throw new Exception("No file name specified");

                //build URI
                string strURI = Product.BaseProductUri + "/words/" + FileName;
                strURI += "/protection";

                //sign URI
                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                ProtectionRequest protectionRequest = new ProtectionRequest();
                protectionRequest.Password = password;
                protectionRequest.ProtectionType = protectionType.ToString();

                string strJSON = JsonConvert.SerializeObject(protectionRequest);

                Stream responseStream = Utils.ProcessCommand(signedURI, "PUT", strJSON);
                StreamReader reader = new StreamReader(responseStream);
                
                //further process JSON response
                string strResponseJSON = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject parsedJSON = JObject.Parse(strResponseJSON);

                //Deserializes the JSON to a object. 
                BaseResponse baseResponse = JsonConvert.DeserializeObject<BaseResponse>(parsedJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                    return true;
                else
                    return false;
            
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemple #4
0
        public bool ProtectWorkbook(ProtectionType protectionType, string password)
        {
            try
            {
                //build URI to get page count
                string strURI    = Product.BaseProductUri + "/cells/" + FileName + "/protection";
                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                Protection protection = new Protection();
                protection.ProtectionType = protectionType.ToString();
                protection.Password       = password;

                string strJSON = JsonConvert.SerializeObject(protection);

                Stream responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);

                StreamReader reader      = new StreamReader(responseStream);
                string       strResponse = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject pJSON = JObject.Parse(strResponse);

                BaseResponse baseResponse = JsonConvert.DeserializeObject <BaseResponse>(pJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public bool ProtectWorkbook(ProtectionType protectionType, string password)
        {
            try
            {
                //build URI to get page count
                string strURI = Product.BaseProductUri + "/cells/" + FileName + "/protection";
                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                Protection protection = new Protection();
                protection.ProtectionType = protectionType.ToString();
                protection.Password = password;

                string strJSON = JsonConvert.SerializeObject(protection);

                Stream responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);

                StreamReader reader = new StreamReader(responseStream);
                string strResponse = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject pJSON = JObject.Parse(strResponse);

                BaseResponse baseResponse = JsonConvert.DeserializeObject<BaseResponse>(pJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public WordsProtectionRequest(string password, string newPassword, ProtectionType protectionType)
 {
     Password = password;
     NewPassword = newPassword;
     ProtectionType = protectionType.ToString();
 }