Exemplo n.º 1
0
        /// <summary>
        /// Get Document's properties
        /// </summary>
        /// <returns>List of document properties</returns>
        public List <DocumentProperty> GetProperties()
        {
            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 += "/documentProperties";

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

                StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "GET"));

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

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

                //Create list of document properties
                List <Aspose.Cloud.Words.DocumentProperty> properties = new List <Aspose.Cloud.Words.DocumentProperty>();

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

                properties = docResponse.DocumentProperties.List;

                //return document properties
                return(properties);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set document property
        /// </summary>
        /// <param name="propertyName">property name</param>
        /// <param name="propertyValue">property value</param>
        public Boolean SetProperty(string propertyName, string propertyValue)
        {
            try
            {
                string strURI    = Product.BaseProductUri + "/words/" + FileName + "/documentProperties/" + propertyName;
                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                DocumentProperty docProperty = new DocumentProperty();
                docProperty.Value = propertyValue;
                string strJSON = JsonConvert.SerializeObject(docProperty);

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

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

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

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

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }