コード例 #1
0
 public static void CreateQuickLaunchMenuHeading(SPWeb spWeb, string title, string url, bool isExternal, QuickLaunchPosition position)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate
                                              {
                                                  using (var site = new SPSite(spWeb.Url))
                                                  {
                                                      SPWeb web = site.AllWebs[spWeb.ID];
                                                      web.AllowUnsafeUpdates = true;
                                                      var node1 = new SPNavigationNode(title, url,
                                                                                                    isExternal);
                                                      if (position == QuickLaunchPosition.AddAtLast)
                                                          web.Navigation.QuickLaunch.AddAsLast(node1);
                                                      else
                                                          web.Navigation.QuickLaunch.AddAsFirst(node1);
                                                      web.Update();
                                                      web.AllowUnsafeUpdates = false;
                                                      web.Update();
                                                  }
                                              });
 }
コード例 #2
0
 public static void CreateQuickLaunchMenuLink(SPWeb spWeb, string title, string url, bool isExternal, string parentHeading, QuickLaunchPosition position)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate
                                              {
                                                  using (var site = new SPSite(spWeb.Url))
                                                  {
                                                      SPWeb web = site.AllWebs[spWeb.ID];
                                                      foreach (SPNavigationNode node in web.Navigation.QuickLaunch)
                                                      {
                                                          if (node.Title == parentHeading)
                                                          {
                                                              web.AllowUnsafeUpdates = true;
                                                              var node1 = new SPNavigationNode(title, url, isExternal);
                                                              if (position == QuickLaunchPosition.AddAtLast)
                                                                  node.Children.AddAsLast(node1);
                                                              else
                                                                  node.Children.AddAsFirst(node1);
                                                              web.Update();
                                                              web.AllowUnsafeUpdates = false;
                                                              web.Update();
                                                              break;
                                                          }
                                                      }
                                                  }
                                              });
 }