当前位置: 首页>>代码示例>>C#>>正文


C# Web.Update方法代码示例

本文整理汇总了C#中Web.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Web.Update方法的具体用法?C# Web.Update怎么用?C# Web.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Web的用法示例。


在下文中一共展示了Web.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LocalizeSiteAndList

        private static void LocalizeSiteAndList(ClientContext cc, Web web)
        {
            // Localize site title
            web.TitleResource.SetValueForUICulture("en-US", "Hello World");
            web.TitleResource.SetValueForUICulture("fi-FI", "Kielikäännä minut");
            web.TitleResource.SetValueForUICulture("fr-FR", "Localize Me to French");
            // Site description
            web.DescriptionResource.SetValueForUICulture("en-US", "Localize Me site sample");
            web.DescriptionResource.SetValueForUICulture("fi-FI", "Kielikäännetty saitti");
            web.DescriptionResource.SetValueForUICulture("fr-FR", "Localize to French in description");
            web.Update();
            cc.ExecuteQuery();

            // Localize custom list which was created previously
            List list = cc.Web.Lists.GetByTitle("LocalizeMe");
            cc.Load(list);
            cc.ExecuteQuery();
            list.TitleResource.SetValueForUICulture("en-US", "Localize Me");
            list.TitleResource.SetValueForUICulture("fi-FI", "Kielikäännä minut");
            list.TitleResource.SetValueForUICulture("fr-FR", "French text for title");
            // Description
            list.DescriptionResource.SetValueForUICulture("en-US", "This is localization CSOM usage example list.");
            list.DescriptionResource.SetValueForUICulture("fi-FI", "Tämä esimerkki näyttää miten voit kielikääntää listoja.");
            list.DescriptionResource.SetValueForUICulture("fr-FR", "I have no idea how to translate this to French.");
            list.Update();
            cc.ExecuteQuery();
        }
开发者ID:CherifSy,项目名称:PnP,代码行数:27,代码来源:Program.cs

示例2: RemovePublishingPage

        private static void RemovePublishingPage(SPPublishing.PublishingPage publishingPage, PublishingPage page, ClientContext ctx, Web web)
        {
            if (publishingPage != null && publishingPage.ServerObjectIsNull.Value == false)
            {
                if (!web.IsPropertyAvailable("RootFolder"))
                {
                    web.Context.Load(web.RootFolder);
                    web.Context.ExecuteQueryRetry();
                }

                if (page.Overwrite)
                {
                    if (page.WelcomePage && web.RootFolder.WelcomePage.Contains(page.FileName + ".aspx"))
                    {
                        //set the welcome page to a Temp page to allow remove the page
                        web.RootFolder.WelcomePage = "home.aspx";
                        web.RootFolder.Update();
                        web.Update();

                        ctx.Load(publishingPage);
                        ctx.ExecuteQuery();
                    }

                    publishingPage.ListItem.DeleteObject();
                    ctx.ExecuteQuery();
                }
                else
                {
                    return;
                }
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:32,代码来源:PageHelper.cs

示例3: SetProperty

        public void SetProperty(ClientContext context, Web webToConfigure, KeyValuePair<string, string> property)
        {
            var webProperties = webToConfigure.AllProperties;
            webProperties[property.Key] = property.Value;

            webToConfigure.Update();
            context.ExecuteQuery();
        }
开发者ID:ceg692001,项目名称:sherpa,代码行数:8,代码来源:PropertyManager.cs

示例4: RecursivelyUpdateWebLogo

 private static void RecursivelyUpdateWebLogo(Web currentWeb)
 {
     Console.WriteLine("Changing " + currentWeb.Title + " site logo URL from " + currentWeb.SiteLogoUrl + " to " + siteLogoUrl + ".");
     Console.WriteLine();
     currentWeb.SiteLogoUrl = siteLogoUrl;
     currentWeb.Update();
     WebCollection subWebs = currentWeb.Webs;
     clientContext.Load(subWebs);
     clientContext.ExecuteQuery();
     foreach (Web subWeb in subWebs)
     {
         RecursivelyUpdateWebLogo(subWeb);
     }
 }
开发者ID:gitter-badger,项目名称:sharepoint,代码行数:14,代码来源:Program.cs

示例5: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                web.IsMultilingual = true;
                web.Context.Load(web, w => w.SupportedUILanguageIds);
                web.Update();
                web.Context.ExecuteQuery();

                var isDirty = false;

                foreach (var id in web.SupportedUILanguageIds)
                {
                    var found = template.SupportedUILanguages.Any(sl => sl.LCID == id);

                    if (!found)
                    {
                        web.RemoveSupportedUILanguage(id);
                        isDirty = true;
                    }
                }
                if (isDirty)
                {
                    web.Update();
                    web.Context.ExecuteQueryRetry();
                }

                foreach (var id in template.SupportedUILanguages)
                {
                    web.AddSupportedUILanguage(id.LCID);
                }
                web.Update();
                web.Context.ExecuteQueryRetry();
            }

            return parser;
        }
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:37,代码来源:ObjectSupportedUILanguages.cs

示例6: SetPropertyBagValue

        public static void SetPropertyBagValue(Web web, string key, string value)
        {
            var context = web.Context;

            if (!web.IsPropertyAvailable("AllProperties"))
            {
                context.Load(web);
                context.Load(web, w => w.AllProperties);
                context.ExecuteQueryWithTrace();
            }

            // weird, this is incorrect
            // https://lixuan0125.wordpress.com/2013/10/18/add-and-retrieve-property-bag-by-csom/

            // if (!web.AllProperties.FieldValues.ContainsKey(key))
            //    web.AllProperties.FieldValues.Add(key, value);
            //else

            web.AllProperties[key] = value;

            web.Update();
            context.ExecuteQueryWithTrace();
        }
开发者ID:sweepheart,项目名称:spmeta2,代码行数:23,代码来源:PageLayoutAndSiteTemplateSettingsModelHandler.cs

示例7: SetDepartmentTitle

 public void SetDepartmentTitle(ClientContext context, Web web)
 {
     web.Title = "Department A";
     web.Update();
     context.ExecuteQuery();
 }
开发者ID:mehrosu,项目名称:SPOEmulators,代码行数:6,代码来源:ProvisioningEngine.cs

示例8: DocumentUpload

 /// <summary>
 /// Upload helper function for uploading documents to SharePoint library.
 /// </summary>
 /// <param name="folderPath">Folder path of Document Library</param>
 /// <param name="listResponse">SharePoint list response</param>
 /// <param name="clientContext">Client context object for connection between SP & client</param>
 /// <param name="documentLibraryName">Name of document library in which upload is to be done</param>
 /// <param name="web">Object of site</param>
 /// <param name="folderName">Target folder name where file needs to be uploaded.</param>
 /// <param name="uploadFile">Object having file creation information</param>
 /// <returns>It returns true if upload is successful else false</returns>
 private GenericResponseVM DocumentUpload(string folderPath, IList<string> listResponse, ClientContext clientContext, string documentLibraryName, Web web, string folderName, FileCreationInformation uploadFile)
 {            
     GenericResponseVM genericResponse = null;
     using (clientContext)
     {
         if (FolderExists(folderPath, clientContext, documentLibraryName))
         {
             Folder destionationFolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath);
             clientContext.Load(destionationFolder);
             clientContext.ExecuteQuery();
             Microsoft.SharePoint.Client.File fileToUpload = destionationFolder.Files.Add(uploadFile);
             destionationFolder.Update();
             web.Update();
             clientContext.Load(fileToUpload);
             clientContext.ExecuteQuery();                    
         }
         else
         {                   
             genericResponse = new GenericResponseVM()
             {
                 Code = errorSettings.FolderStructureModified,
                 Value = folderName,
                 IsError = true
             };
         }
     }
     return genericResponse;
 }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:39,代码来源:SPList.cs

示例9: ApplyThemeToSite

        private void ApplyThemeToSite(Web hostWeb, Web newWeb)
        {
            // Let's first upload the contoso theme to host web, if it does not exist there
            newWeb.DeployThemeToSubWeb(hostWeb, "TechEd",
                            HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/Themes/TechEd/teched.spcolor")),
                            null,
                            HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/Themes/TechEd/bg.jpg")),
                            string.Empty);

            // Setting the Contoos theme to host web
            newWeb.SetThemeToWeb("TechEd");

            // Instance to site assets. Notice that this is using hard coded list name which only works in 1033 sites
            List assetLibrary = newWeb.Lists.GetByTitle("Site Assets");
            newWeb.Context.Load(assetLibrary, l => l.RootFolder);

            // Get the path to the file which we are about to deploy
            string logoFile = System.Web.Hosting.HostingEnvironment.MapPath(
                                string.Format("~/{0}", "Resources/Themes/TechEd/logo.png"));

            // Use CSOM to upload the file in
            FileCreationInformation newFile = new FileCreationInformation();
            newFile.Content = System.IO.File.ReadAllBytes(logoFile);
            newFile.Url = "pnp.png";
            newFile.Overwrite = true;
            File uploadFile = assetLibrary.RootFolder.Files.Add(newFile);
            newWeb.Context.Load(uploadFile);
            newWeb.Context.ExecuteQuery();

            newWeb.AlternateCssUrl = newWeb.ServerRelativeUrl + "/SiteAssets/contoso.css";
            newWeb.SiteLogoUrl = newWeb.ServerRelativeUrl + "/SiteAssets/pnp.png";
            newWeb.Update();
            newWeb.Context.ExecuteQuery();
        }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:34,代码来源:Default.aspx.cs

示例10: RemovePropertyBagValueInternal

        /// <summary>
        /// Removes a property bag value
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="key">They key to remove</param>
        /// <param name="checkIndexed"></param>
        private static void RemovePropertyBagValueInternal(Web web, string key, bool checkIndexed)
        {
            // In order to remove a property from the property bag, remove it both from the AllProperties collection by setting it to null
            // -and- by removing it from the FieldValues collection. Bug in CSOM?
            web.AllProperties[key] = null;
            web.AllProperties.FieldValues.Remove(key);

            web.Update();

            web.Context.ExecuteQueryRetry();
            if (checkIndexed)
                RemoveIndexedPropertyBagKey(web, key); // Will only remove it if it exists as an indexed property
        }
开发者ID:OfficeDev,项目名称:PnP-Sites-Core,代码行数:19,代码来源:WebExtensions.cs

示例11: SetPropertyBagValueInternal

        /// <summary>
        /// Sets a key/value pair in the web property bag
        /// </summary>
        /// <param name="web">Web that will hold the property bag entry</param>
        /// <param name="key">Key for the property bag entry</param>
        /// <param name="value">Value for the property bag entry</param>
        private static void SetPropertyBagValueInternal(Web web, string key, object value)
        {
            var props = web.AllProperties;
            web.Context.Load(props);
            web.Context.ExecuteQuery();

            props[key] = value;

            web.Update();
            web.Context.ExecuteQuery();
        }
开发者ID:JohnKozell,项目名称:PnP,代码行数:17,代码来源:WebExtensions.cs

示例12: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                if (template.WebSettings != null)
                {
                    // Check if this is not a noscript site as we're not allowed to update some properties
                    bool isNoScriptSite = web.IsNoScriptSite();

                    web.EnsureProperty(w => w.HasUniqueRoleAssignments);

                    var webSettings = template.WebSettings;
            #if !ONPREMISES
                    if (!isNoScriptSite)
                    {
                        web.NoCrawl = webSettings.NoCrawl;
                    }
                    else
                    {
                        scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipNoCrawlUpdate);
                    }

                    if (!web.IsSubSite() || (web.IsSubSite() && web.HasUniqueRoleAssignments))
                    {
                        String requestAccessEmailValue = parser.ParseString(webSettings.RequestAccessEmail);
                        if (!String.IsNullOrEmpty(requestAccessEmailValue) && requestAccessEmailValue.Length >= 255)
                        {
                            requestAccessEmailValue = requestAccessEmailValue.Substring(0, 255);
                        }
                        if (!String.IsNullOrEmpty(requestAccessEmailValue))
                        {
                            web.RequestAccessEmail = requestAccessEmailValue;

                            web.Update();
                            web.Context.ExecuteQueryRetry();
                        }
                    }
            #endif
                    var masterUrl = parser.ParseString(webSettings.MasterPageUrl);
                    if (!string.IsNullOrEmpty(masterUrl))
                    {
                        if (!isNoScriptSite)
                        {
                            web.MasterUrl = masterUrl;
                        }
                        else
                        {
                            scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipMasterPageUpdate);
                        }
                    }
                    var customMasterUrl = parser.ParseString(webSettings.CustomMasterPageUrl);
                    if (!string.IsNullOrEmpty(customMasterUrl))
                    {
                        if (!isNoScriptSite)
                        {
                            web.CustomMasterUrl = customMasterUrl;
                        }
                        else
                        {
                            scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipCustomMasterPageUpdate);
                        }
                    }
                    if (webSettings.Title != null)
                    {
                        web.Title = parser.ParseString(webSettings.Title);
                    }
                    if (webSettings.Description != null)
                    {
                        web.Description = parser.ParseString(webSettings.Description);
                    }
                    if (webSettings.SiteLogo != null)
                    {
                        web.SiteLogoUrl = parser.ParseString(webSettings.SiteLogo);
                    }
                    var welcomePage = parser.ParseString(webSettings.WelcomePage);
                    if (!string.IsNullOrEmpty(welcomePage))
                    {
                        web.RootFolder.WelcomePage = welcomePage;
                        web.RootFolder.Update();
                    }
                    if (webSettings.AlternateCSS != null)
                    {
                        web.AlternateCssUrl = parser.ParseString(webSettings.AlternateCSS);
                    }

                    web.Update();
                    web.Context.ExecuteQueryRetry();
                }
            }

            return parser;
        }
开发者ID:s-KaiNet,项目名称:PnP-Sites-Core,代码行数:92,代码来源:ObjectWebSettings.cs

示例13: SetAlternateCssUrlForWeb

 private static void SetAlternateCssUrlForWeb(ClientContext context, ShWeb configWeb, Web webToConfigure)
 {
     if (!string.IsNullOrEmpty(configWeb.AlternateCssUrl))
     {
         Log.Debug("Setting AlternateCssUrl for web " + configWeb.Name);
         webToConfigure.AlternateCssUrl = ContentUploadManager.GetPropertyValueWithTokensReplaced(configWeb.AlternateCssUrl, context);
         webToConfigure.Update();
         context.ExecuteQuery();
     }
 }
开发者ID:damsleth,项目名称:sherpa,代码行数:10,代码来源:SiteSetupManager.cs

示例14: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                if (template.WebSettings != null)
                {
                    var webSettings = template.WebSettings;
#if !CLIENTSDKV15
                    web.NoCrawl = webSettings.NoCrawl;

                    String requestAccessEmailValue = parser.ParseString(webSettings.RequestAccessEmail);
                    if (!String.IsNullOrEmpty(requestAccessEmailValue) && requestAccessEmailValue.Length >= 255)
                    {
                        requestAccessEmailValue = requestAccessEmailValue.Substring(0, 255);
                    }
                    if (!String.IsNullOrEmpty(requestAccessEmailValue))
                    {
                        web.RequestAccessEmail = requestAccessEmailValue;
                    }
#endif
                    var masterUrl = parser.ParseString(webSettings.MasterPageUrl);
                    if (!string.IsNullOrEmpty(masterUrl))
                    {
                        web.MasterUrl = masterUrl;
                    }
                    var customMasterUrl = parser.ParseString(webSettings.CustomMasterPageUrl);
                    if (!string.IsNullOrEmpty(customMasterUrl))
                    {
                        web.CustomMasterUrl = customMasterUrl;
                    }
                    web.Description = parser.ParseString(webSettings.Description);
                    web.SiteLogoUrl = parser.ParseString(webSettings.SiteLogo);
                    var welcomePage = parser.ParseString(webSettings.WelcomePage);
                    if (!string.IsNullOrEmpty(welcomePage))
                    {
                        web.RootFolder.WelcomePage = welcomePage;
                        web.RootFolder.Update();
                    }
                    web.AlternateCssUrl = parser.ParseString(webSettings.AlternateCSS);

                    web.Update();
                    web.Context.ExecuteQueryRetry();
                }
            }

            return parser;
        }
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:47,代码来源:ObjectWebSettings.cs

示例15: ProvisionSample3

        void ProvisionSample3(Web web)
        {
            //Delete list if it already exists
            ListCollection lists = web.Lists;
            IEnumerable<List> results = web.Context.LoadQuery<List>(lists.Where(list => list.Title == "CSR-Confidential-Documents"));
            web.Context.ExecuteQuery();
            List existingList = results.FirstOrDefault();

            if (existingList != null)
            {
                existingList.DeleteObject();
                web.Context.ExecuteQuery();
            }

            //Create list
            ListCreationInformation creationInfo = new ListCreationInformation();
            creationInfo.Title = "CSR-Confidential-Documents";
            creationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
            List newlist = web.Lists.Add(creationInfo);
            newlist.Update();
            web.Context.Load(newlist);
            web.Context.Load(newlist.Fields);
            web.Context.ExecuteQuery();

            //Add field
            FieldCollection fields = web.Fields;
            web.Context.Load(fields, fc => fc.Include(f => f.InternalName));
            web.Context.ExecuteQuery();
            Field field = fields.FirstOrDefault(f => f.InternalName == "Confidential");
            if (field == null)
            {
                field = newlist.Fields.AddFieldAsXml("<Field Type=\"YES/NO\" Name=\"Confidential\" DisplayName=\"Confidential\" ID=\"" + Guid.NewGuid() + "\" Group=\"CSR Samples\" />", false, AddFieldOptions.DefaultValue);
                web.Update();
                web.Context.ExecuteQuery();
            }
            newlist.Fields.Add(field);
            newlist.Update();
            web.Context.ExecuteQuery();

            //Upload sample docs
            UploadTempDoc(newlist, "Doc1.doc");
            UploadTempDoc(newlist, "Doc2.doc");
            UploadTempDoc(newlist, "Doc3.ppt");
            UploadTempDoc(newlist, "Doc4.ppt");
            UploadTempDoc(newlist, "Doc5.xls");
            UploadTempDoc(newlist, "Doc6.xls");
            Microsoft.SharePoint.Client.ListItem item1 = newlist.GetItemById(1);
            item1["Confidential"] = 1;
            item1.Update();
            Microsoft.SharePoint.Client.ListItem item2 = newlist.GetItemById(2);
            item2["Confidential"] = 1;
            item2.Update();
            Microsoft.SharePoint.Client.ListItem item3 = newlist.GetItemById(3);
            item3["Confidential"] = 0;
            item3.Update();
            Microsoft.SharePoint.Client.ListItem item4 = newlist.GetItemById(4);
            item4["Confidential"] = 1;
            item4.Update();
            Microsoft.SharePoint.Client.ListItem item5 = newlist.GetItemById(5);
            item5["Confidential"] = 0;
            item5.Update();
            Microsoft.SharePoint.Client.ListItem item6 = newlist.GetItemById(6);
            item6["Confidential"] = 1;
            item6.Update();
            web.Context.ExecuteQuery();

            //Create sample view
            ViewCreationInformation sampleViewCreateInfo = new ViewCreationInformation();
            sampleViewCreateInfo.Title = "CSR Sample View";
            sampleViewCreateInfo.ViewFields = new string[] { "DocIcon", "LinkFilename", "Modified", "Editor", "Confidential" };
            sampleViewCreateInfo.SetAsDefaultView = true;
            Microsoft.SharePoint.Client.View sampleView = newlist.Views.Add(sampleViewCreateInfo);
            sampleView.Update();
            web.Context.Load(newlist, l => l.DefaultViewUrl);
            web.Context.ExecuteQuery();

            //Register JS files via JSLink properties
            RegisterJStoWebPart(web, newlist.DefaultViewUrl, "~sitecollection/Style Library/JSLink-Samples/ConfidentialDocuments.js");
        }
开发者ID:tandis,项目名称:PnP,代码行数:79,代码来源:Default.aspx.cs


注:本文中的Web.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。