コード例 #1
0
        /// <summary>
        /// Item updating sample using Sitecore query
        /// </summary>
        /// <para>
        ///     Requires an authenticated data context
        /// </para>
        /// <para>
        ///     The user must have write permissions on the item
        /// </para>
        /// <param name="context">The context.</param>
        private static void UpdateItemExpressionSample(AuthenticatedSitecoreDataContext context)
        {
            var query = new SitecoreExpressionQuery(SitecoreQueryType.Update)
            {
                Query = "/sitecore/content/Home",
                QueryScope = new[]
                                 {
                                     SitecoreItemScope.Self
                                 },
                Database = "master",
                FieldsToUpdate = new Dictionary<string, string>
                                                   {
                                                       { "Field Name", "Value" },
                                                       { "{11111111-1111-1111-1111-111111111111}", "Value" }
                                                   },
                FieldsToReturn = new List<string>
                                                    {
                                                        "Field Name",
                                                        "{11111111-1111-1111-1111-111111111111}"
                                                    }
            };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                foreach (WebApiItem item in response.Result.Items)
                {
                    Wl("path", item.Path);
                    WriteFields(item);
                }
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }
コード例 #2
0
        private static void ExpressionQuerySample(SitecoreDataContext context)
        {
            var query = new SitecoreExpressionQuery(SitecoreQueryType.Read)
                                      {
                                          Query = "/sitecore/content/Home/*",
                                          Payload = SitecorePayload.Min,
                                          QueryScope = new[] { SitecoreItemScope.Self }
                                      };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                foreach (WebApiItem item in response.Result.Items)
                {
                    Wl("path", item.Path);
                }
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }