コード例 #1
0
        /// <summary>
        /// Check all webpart in the specified webpartpage
        /// </summary>
        /// <param name="CurrentFile"></param>
        protected void CrawlWebPartPage(SPFile CurrentFile)
        {
            using (SPWeb web = CurrentFile.ParentFolder.ParentWeb)
            {
                SPWebPartCollection parts = web.GetWebPartCollection(CurrentFile.Url, Storage.Shared);
                if (parts != null)
                {
                    //OnTrace("Start search " + CurrentFile.Url.ToString() + " webpart's page...", "");

                    for (int i = 0; i < parts.Count; i++)
                    {
                        using (WebPart wptWebPart = parts[i])
                        {
                            if (WebPartInWebPartList(wptWebPart))
                            {
                                string[] webPartNames     = wptWebPart.ToString().Split('.');
                                string   WebPartSmallName = webPartNames[webPartNames.Length - 1].ToString();

                                OnTrace("Start search webpart " + WebPartSmallName, "");

                                try
                                {
                                    PropertyInfo[] pinProperties = wptWebPart.GetType().GetProperties(
                                        BindingFlags.Public | BindingFlags.Instance);

                                    try
                                    {
                                        foreach (PropertyInfo p in pinProperties)
                                        {
                                            if (FindReplaceWebPartProperty(wptWebPart, p))
                                            {
                                                parts.SaveChanges(wptWebPart.StorageKey);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        string sre = ex.Message;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string s = ex.Message;
                                }

                                OnTrace("Finish search webpart " + WebPartSmallName, "");
                            }
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                        }
                    }
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            //OnTrace("Finish search " + CurrentFile.Url.ToString() + " webpart's page...", "");
        }
コード例 #2
0
 public void PersistProperties()
 {
     try
     {
         SPWeb  web  = ForumApplication.Instance.SpWeb;
         SPFile file = web.GetFile(this.Context.Request.Path);
         SPWebPartCollection webPartCollection = file.GetWebPartCollection(Storage.Shared);
         web.AllowUnsafeUpdates = true;
         //this.SaveProperties = true;
         webPartCollection.SaveChanges(this.StorageKey);
     }
     catch (Exception ex)
     {
         AddError(ex);
     }
 }