kamagra how much to take

Move List SharePoint WebPart

This example shows you how to move a list within an arbitrary number of webs in SharePoint.

  1. [DefaultProperty("Text"), XmlRoot(Namespace = "MoveList"), ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>")]
  2. public class MoveList : WebPart
  3. {
  4.         public MoveList()
  5.         {
  6.                 this._text = "";
  7.         }
  8.  
  9.         protected void btnGetWebs_Click(object sender, EventArgs e)
  10.         {
  11.                 this.GetAvailableSubWebs();
  12.         }
  13.  
  14.         protected override void CreateChildControls()
  15.         {
  16.                 this.txtMessage = new Label();
  17.                 this.Controls.Add(this.txtMessage);
  18.                 this.txtList1 = new TextBox();
  19.                 this.Controls.Add(this.txtList1);
  20.                 this.txtList2 = new TextBox();
  21.                 this.Controls.Add(this.txtList2);
  22.                 this.txtWeb1 = new TextBox();
  23.                 this.Controls.Add(this.txtWeb1);
  24.                 this.txtWeb2 = new TextBox();
  25.                 this.Controls.Add(this.txtWeb2);
  26.                 this.btnGetLists = new Button();
  27.                 this.btnGetLists.Text = "Get Lists";
  28.                 this.Controls.Add(this.btnGetLists);
  29.                 this.btnGetWebs = new Button();
  30.                 this.btnGetWebs.Text = "Get Webs";
  31.                 this.Controls.Add(this.btnGetWebs);
  32.                 this.btnSubmit = new Button();
  33.                 this.btnSubmit.Text = "Move List";
  34.                 this.Controls.Add(this.btnSubmit);
  35.                 this.ddlLists = new DropDownList();
  36.                 this.Controls.Add(this.ddlLists);
  37.                 this.ddlSourceWeb = new DropDownList();
  38.                 this.Controls.Add(this.ddlSourceWeb);
  39.                 this.ddlDestinationWeb = new DropDownList();
  40.                 this.Controls.Add(this.ddlDestinationWeb);
  41.                 this.chbIncludeDocs = new CheckBox();
  42.                 this.chbIncludeDocs.Text = "Include Data/Documents";
  43.                 this.Controls.Add(this.chbIncludeDocs);
  44.         }
  45.  
  46.         protected void GetAvailableSubWebs()
  47.         {
  48.                 SPSite site1 = SPControl.GetContextSite(this.Context);
  49.                 this.ddlSourceWeb.Items.Clear();
  50.                 this.ddlDestinationWeb.Items.Clear();
  51.                 foreach (SPWeb web1 in site1.AllWebs)
  52.                 {
  53.                         ListItem item1 = new ListItem(web1.ToString() + " (" + web1.Url + ")", web1.ServerRelativeUrl);
  54.                         this.ddlSourceWeb.Items.Add(item1);
  55.                         this.ddlDestinationWeb.Items.Add(item1);
  56.                 }
  57.         }
  58.  
  59.         protected void GetAvailableWebs()
  60.         {
  61.                 IEnumerator enumerator2;
  62.                 SPSite site1 = SPControl.GetContextSite(this.Context);
  63.                 SPGlobalAdmin admin1 = new SPGlobalAdmin();
  64.                 Uri uri1 = new Uri(site1.RootWeb.Url.ToString());
  65.                 SPVirtualServer server1 = admin1.OpenVirtualServer(uri1);
  66.                 try
  67.                 {
  68.                         enumerator2 = server1.Sites.GetEnumerator();
  69.                         while (enumerator2.MoveNext())
  70.                         {
  71.                                 site1 = (SPSite)enumerator2.Current;
  72.                                 try
  73.                                 {
  74.                                         foreach (SPWeb web1 in site1.AllWebs)
  75.                                         {
  76.                                                 ListItem item1 = new ListItem(web1.ToString() + " (" + web1.Url + ")", web1.ServerRelativeUrl);
  77.                                                 this.ddlSourceWeb.Items.Add(item1);
  78.                                                 this.ddlDestinationWeb.Items.Add(item1);
  79.                                         }
  80.                                 }
  81.                                 finally
  82.                                 {
  83.                                         IEnumerator enumerator1;
  84.                                         if (enumerator1 is IDisposable)
  85.                                         {
  86.                                                 ((IDisposable)enumerator1).Dispose();
  87.                                         }
  88.                                 }
  89.                         }
  90.                 }
  91.                 finally
  92.                 {
  93.                         if (enumerator2 is IDisposable)
  94.                         {
  95.                                 ((IDisposable)enumerator2).Dispose();
  96.                         }
  97.                 }
  98.         }
  99.  
  100.         protected void GetLists(object Sender, EventArgs e)
  101.         {
  102.                 SPSite site1 = new SPSite("<a href="http://localhost/">http://localhost</a>");
  103.                 SPGlobalAdmin admin1 = new SPGlobalAdmin();
  104.                 Uri uri1 = new Uri(site1.Url);
  105.                 this.txtMessage.Text = this.ddlSourceWeb.SelectedItem.Value.ToString();
  106.                 SPVirtualServer server1 = admin1.VirtualServers[0];
  107.                 site1 = server1.Sites[this.ddlSourceWeb.SelectedItem.Value.ToString()];
  108.                 SPWeb web1 = site1.AllWebs[this.ddlSourceWeb.SelectedItem.Value.ToString()];
  109.                 this.ddlLists.Items.Clear();
  110.                 foreach (SPList list1 in web1.Lists)
  111.                 {
  112.                         ListItem item1 = new ListItem(list1.ToString(), list1.ToString());
  113.                         this.ddlLists.Items.Add(item1);
  114.                 }
  115.         }
  116.  
  117.         protected void MoveList(object sender, EventArgs e)
  118.         {
  119.                 SPListTemplate template1;
  120.                 SPSite site1 = new SPSite("<a href="http://localhost/">http://localhost/</a>" + this.ddlSourceWeb.SelectedItem.Value);
  121.                 SPWeb web2 = site1.AllWebs[this.ddlSourceWeb.SelectedItem.Value];
  122.                 SPList list2 = web2.Lists[this.ddlLists.SelectedItem.Value.ToString()];
  123.                 this.txtMessage.Text = "";
  124.                 try
  125.                 {
  126.                         list2.SaveAsTemplate(list2.Title.ToString(), list2.Title.ToString(), "test", this.chbIncludeDocs.Checked);
  127.                 }
  128.                 catch (Exception exception1)
  129.                 {
  130.                         ProjectData.SetProjectError(exception1);
  131.                         this.txtMessage.Text = this.txtMessage.Text + "A Template with this name already exsists, using previous template as basis for new list&lt;/br&gt;";
  132.                         ProjectData.ClearProjectError();
  133.                 }
  134.                 SPSite site2 = new SPSite("<a href="http://localhost/">http://localhost/</a>" + this.ddlDestinationWeb.SelectedItem.Value);
  135.                 SPWeb web1 = site2.AllWebs[this.ddlDestinationWeb.SelectedItem.Value];
  136.                 SPListTemplateCollection collection1 = site1.GetCustomListTemplates(site1.AllWebs[this.ddlSourceWeb.SelectedItem.Value]);
  137.                 try
  138.                 {
  139.                         template1 = collection1[list2.Title.ToString()];
  140.                 }
  141.                 catch (Exception exception2)
  142.                 {
  143.                         ProjectData.SetProjectError(exception2);
  144.                         this.txtMessage.Text = this.txtMessage.Text + "Error Getting Template &lt;/br&gt;";
  145.                         ProjectData.ClearProjectError();
  146.                 }
  147.                 web1.Lists.Add(list2.Title, list2.Description, template1);
  148.                 this.txtMessage.Text = this.txtMessage.Text + "Template with name &lt;strong&gt;" + list2.Title.ToString() + ".stp&lt;/strong&gt; may de deleted from the default list template gallery";
  149.         }
  150.  
  151.         protected override void RenderWebPart(HtmlTextWriter output)
  152.         {
  153.                 output.Write(SPEncode.HtmlEncode(this.Text));
  154.                 this.txtMessage.RenderControl(output);
  155.                 output.Write("&lt;TABLE width=\"100%\" cellpadding=\"5\"&gt;");
  156.                 output.WriteLine("&lt;TR&gt;");
  157.                 output.WriteLine("&lt;TD&gt;");
  158.                 output.Write("&lt;strong&gt;Step 1:&lt;/strong&gt;");
  159.                 output.WriteLine("&lt;/TD&gt;");
  160.                 output.WriteLine("&lt;TD&gt;");
  161.                 output.WriteLine("&lt;/TD&gt;");
  162.                 output.WriteLine("&lt;/TR&gt;");
  163.                 output.WriteLine("&lt;TR&gt;");
  164.                 output.WriteLine("&lt;TD&gt;");
  165.                 output.Write("Find Available Webs");
  166.                 output.WriteLine("&lt;/TD&gt;");
  167.                 output.WriteLine("&lt;TD&gt;");
  168.                 this.btnGetWebs.RenderControl(output);
  169.                 output.WriteLine("&lt;/TD&gt;");
  170.                 output.WriteLine("&lt;/TR&gt;");
  171.                 output.WriteLine("&lt;TR&gt;");
  172.                 output.WriteLine("&lt;TD&gt;");
  173.                 output.Write("&lt;strong&gt;Step 2:&lt;/strong&gt;");
  174.                 output.WriteLine("&lt;/TD&gt;");
  175.                 output.WriteLine("&lt;TD&gt;");
  176.                 output.Write("");
  177.                 output.WriteLine("&lt;/TD&gt;");
  178.                 output.WriteLine("&lt;/TR&gt;");
  179.                 output.WriteLine("&lt;TR&gt;");
  180.                 output.WriteLine("&lt;TD&gt;");
  181.                 output.Write("Select Source Web");
  182.                 output.WriteLine("&lt;/TD&gt;");
  183.                 output.WriteLine("&lt;TD&gt;");
  184.                 this.ddlSourceWeb.RenderControl(output);
  185.                 output.WriteLine("&lt;/TD&gt;");
  186.                 output.WriteLine("&lt;/TR&gt;");
  187.                 output.WriteLine("&lt;TR&gt;");
  188.                 output.WriteLine("&lt;TD&gt;");
  189.                 output.Write("&lt;strong&gt;Step 3:&lt;/strong&gt;");
  190.                 output.WriteLine("&lt;/TD&gt;");
  191.                 output.WriteLine("&lt;TD&gt;");
  192.                 output.WriteLine("&lt;/TD&gt;");
  193.                 output.WriteLine("&lt;/TR&gt;");
  194.                 output.WriteLine("&lt;TR&gt;");
  195.                 output.WriteLine("&lt;TD&gt;");
  196.                 output.Write("Get Lists On Source Web");
  197.                 output.WriteLine("&lt;/TD&gt;");
  198.                 output.WriteLine("&lt;TD&gt;");
  199.                 this.btnGetLists.RenderControl(output);
  200.                 output.WriteLine("&lt;/TD&gt;");
  201.                 output.WriteLine("&lt;/TR&gt;");
  202.                 output.WriteLine("&lt;TR&gt;");
  203.                 output.WriteLine("&lt;TD&gt;");
  204.                 output.Write("&lt;strong&gt;Step 4:&lt;/strong&gt;");
  205.                 output.WriteLine("&lt;/TD&gt;");
  206.                 output.WriteLine("&lt;TD&gt;");
  207.                 output.Write("");
  208.                 output.WriteLine("&lt;/TD&gt;");
  209.                 output.WriteLine("&lt;/TR&gt;");
  210.                 output.WriteLine("&lt;TR&gt;");
  211.                 output.WriteLine("&lt;TD&gt;");
  212.                 output.Write("Select Source List To Copy");
  213.                 output.WriteLine("&lt;/TD&gt;");
  214.                 output.WriteLine("&lt;TD&gt;");
  215.                 this.ddlLists.RenderControl(output);
  216.                 output.WriteLine("&lt;/TD&gt;");
  217.                 output.WriteLine("&lt;/TR&gt;");
  218.                 output.WriteLine("&lt;TR&gt;");
  219.                 output.WriteLine("&lt;TD&gt;");
  220.                 output.Write("&lt;strong&gt;Step 5:&lt;/strong&gt;");
  221.                 output.WriteLine("&lt;/TD&gt;");
  222.                 output.WriteLine("&lt;TD&gt;");
  223.                 output.Write("");
  224.                 output.WriteLine("&lt;/TD&gt;");
  225.                 output.WriteLine("&lt;/TR&gt;");
  226.                 output.WriteLine("&lt;TR&gt;");
  227.                 output.WriteLine("&lt;TD&gt;");
  228.                 output.Write("Select Destination Web Where the List Will Be Copied To");
  229.                 output.WriteLine("&lt;/TD&gt;");
  230.                 output.WriteLine("&lt;TD&gt;");
  231.                 this.ddlDestinationWeb.RenderControl(output);
  232.                 output.WriteLine("&lt;/TD&gt;");
  233.                 output.WriteLine("&lt;/TR&gt;");
  234.                 output.WriteLine("&lt;TR&gt;");
  235.                 output.WriteLine("&lt;TD&gt;");
  236.                 output.Write("&lt;strong&gt;Step 6:&lt;/strong&gt;");
  237.                 output.WriteLine("&lt;/TD&gt;");
  238.                 output.WriteLine("&lt;TD&gt;");
  239.                 output.Write("");
  240.                 output.WriteLine("&lt;/TD&gt;");
  241.                 output.WriteLine("&lt;/TR&gt;");
  242.                 output.WriteLine("&lt;TR&gt;");
  243.                 output.WriteLine("&lt;TD&gt;");
  244.                 output.Write("Should the Data/Documents Be Included in the Copy?");
  245.                 output.WriteLine("&lt;/TD&gt;");
  246.                 output.WriteLine("&lt;TD&gt;");
  247.                 this.chbIncludeDocs.RenderControl(output);
  248.                 output.WriteLine("&lt;/TD&gt;");
  249.                 output.WriteLine("&lt;/TR&gt;");
  250.                 output.WriteLine("&lt;TR&gt;");
  251.                 output.WriteLine("&lt;TD&gt;");
  252.                 output.WriteLine("&lt;/TD&gt;");
  253.                 output.WriteLine("&lt;TD&gt;");
  254.                 this.btnSubmit.RenderControl(output);
  255.                 output.WriteLine("&lt;/TD&gt;");
  256.                 output.WriteLine("&lt;/TR&gt;");
  257.                 output.WriteLine("&lt;/TABLE&gt;");
  258.         }
  259.         protected virtual Button btnGetLists
  260.         {
  261.                 get
  262.                 {
  263.                         return this._btnGetLists;
  264.                 }
  265.                 [MethodImpl(MethodImplOptions.Synchronized)]
  266.                 set
  267.                 {
  268.                         if (this._btnGetLists != null)
  269.                         {
  270.                                 this._btnGetLists.Click -= new EventHandler(this.GetLists);
  271.                         }
  272.                         this._btnGetLists = value;
  273.                         if (this._btnGetLists != null)
  274.                         {
  275.                                 this._btnGetLists.Click += new EventHandler(this.GetLists);
  276.                         }
  277.                 }
  278.         }
  279.  
  280.         protected virtual Button btnGetWebs
  281.         {
  282.                 get
  283.                 {
  284.                         return this._btnGetWebs;
  285.                 }
  286.                 [MethodImpl(MethodImplOptions.Synchronized)]
  287.                 set
  288.                 {
  289.                         if (this._btnGetWebs != null)
  290.                         {
  291.                                 this._btnGetWebs.Click -= new EventHandler(this.btnGetWebs_Click);
  292.                         }
  293.                         this._btnGetWebs = value;
  294.                         if (this._btnGetWebs != null)
  295.                         {
  296.                                 this._btnGetWebs.Click += new EventHandler(this.btnGetWebs_Click);
  297.                         }
  298.                 }
  299.         }
  300.  
  301.         protected virtual Button btnSubmit
  302.         {
  303.                 get
  304.                 {
  305.                         return this._btnSubmit;
  306.                 }
  307.                 [MethodImpl(MethodImplOptions.Synchronized)]
  308.                 set
  309.                 {
  310.                         if (this._btnSubmit != null)
  311.                         {
  312.                                 this._btnSubmit.Click -= new EventHandler(this.MoveList);
  313.                         }
  314.                         this._btnSubmit = value;
  315.                         if (this._btnSubmit != null)
  316.                         {
  317.                                 this._btnSubmit.Click += new EventHandler(this.MoveList);
  318.                         }
  319.                 }
  320.         }
  321.  
  322.         protected virtual CheckBox chbIncludeDocs
  323.         {
  324.                 get
  325.                 {
  326.                         return this._chbIncludeDocs;
  327.                 }
  328.                 [MethodImpl(MethodImplOptions.Synchronized)]
  329.                 set
  330.                 {
  331.                         if (this._chbIncludeDocs != null)
  332.                         {
  333.                         }
  334.                         this._chbIncludeDocs = value;
  335.                         if (this._chbIncludeDocs != null)
  336.                         {
  337.                         }
  338.                 }
  339.         }
  340.  
  341.         protected virtual DropDownList ddlDestinationWeb
  342.         {
  343.                 get
  344.                 {
  345.                         return this._ddlDestinationWeb;
  346.                 }
  347.                 [MethodImpl(MethodImplOptions.Synchronized)]
  348.                 set
  349.                 {
  350.                         if (this._ddlDestinationWeb != null)
  351.                         {
  352.                         }
  353.                         this._ddlDestinationWeb = value;
  354.                         if (this._ddlDestinationWeb != null)
  355.                         {
  356.                         }
  357.                 }
  358.         }
  359.  
  360.         protected virtual DropDownList ddlLists
  361.         {
  362.                 get
  363.                 {
  364.                         return this._ddlLists;
  365.                 }
  366.                 [MethodImpl(MethodImplOptions.Synchronized)]
  367.                 set
  368.                 {
  369.                         if (this._ddlLists != null)
  370.                         {
  371.                         }
  372.                         this._ddlLists = value;
  373.                         if (this._ddlLists != null)
  374.                         {
  375.                         }
  376.                 }
  377.         }
  378.  
  379.         protected virtual DropDownList ddlSourceWeb
  380.         {
  381.                 get
  382.                 {
  383.                         return this._ddlSourceWeb;
  384.                 }
  385.                 [MethodImpl(MethodImplOptions.Synchronized)]
  386.                 set
  387.                 {
  388.                         if (this._ddlSourceWeb != null)
  389.                         {
  390.                         }
  391.                         this._ddlSourceWeb = value;
  392.                         if (this._ddlSourceWeb != null)
  393.                         {
  394.                         }
  395.                 }
  396.         }
  397.  
  398.         [Browsable(true), FriendlyName("Text"), WebPartStorage(Storage.Personal), DefaultValue(""), Category("Miscellaneous"), Description("Text Property")]
  399.         public string Text
  400.         {
  401.                 get
  402.                 {
  403.                         return this._text;
  404.                 }
  405.                 set
  406.                 {
  407.                         this._text = value;
  408.                 }
  409.         }
  410.  
  411.         protected virtual TextBox txtList1
  412.         {
  413.                 get
  414.                 {
  415.                         return this._txtList1;
  416.                 }
  417.                 [MethodImpl(MethodImplOptions.Synchronized)]
  418.                 set
  419.                 {
  420.                         if (this._txtList1 != null)
  421.                         {
  422.                         }
  423.                         this._txtList1 = value;
  424.                         if (this._txtList1 != null)
  425.                         {
  426.                         }
  427.                 }
  428.         }
  429.  
  430.         protected virtual TextBox txtList2
  431.         {
  432.                 get
  433.                 {
  434.                         return this._txtList2;
  435.                 }
  436.                 [MethodImpl(MethodImplOptions.Synchronized)]
  437.                 set
  438.                 {
  439.                         if (this._txtList2 != null)
  440.                         {
  441.                         }
  442.                         this._txtList2 = value;
  443.                         if (this._txtList2 != null)
  444.                         {
  445.                         }
  446.                 }
  447.         }
  448.  
  449.         protected virtual Label txtMessage
  450.         {
  451.                 get
  452.                 {
  453.                         return this._txtMessage;
  454.                 }
  455.                 [MethodImpl(MethodImplOptions.Synchronized)]
  456.                 set
  457.                 {
  458.                         if (this._txtMessage != null)
  459.                         {
  460.                         }
  461.                         this._txtMessage = value;
  462.                         if (this._txtMessage != null)
  463.                         {
  464.                         }
  465.                 }
  466.         }
  467.  
  468.         protected virtual TextBox txtWeb1
  469.         {
  470.                 get
  471.                 {
  472.                         return this._txtWeb1;
  473.                 }
  474.                 [MethodImpl(MethodImplOptions.Synchronized)]
  475.                 set
  476.                 {
  477.                         if (this._txtWeb1 != null)
  478.                         {
  479.                         }
  480.                         this._txtWeb1 = value;
  481.                         if (this._txtWeb1 != null)
  482.                         {
  483.                         }
  484.                 }
  485.         }
  486.  
  487.         protected virtual TextBox txtWeb2
  488.         {
  489.                 get
  490.                 {
  491.                         return this._txtWeb2;
  492.                 }
  493.                 [MethodImpl(MethodImplOptions.Synchronized)]
  494.                 set
  495.                 {
  496.                         if (this._txtWeb2 != null)
  497.                         {
  498.                         }
  499.                         this._txtWeb2 = value;
  500.                         if (this._txtWeb2 != null)
  501.                         {
  502.                         }
  503.                 }
  504.         }
  505.         [AccessedThroughProperty("btnGetLists")]
  506.         private Button _btnGetLists;
  507.         [AccessedThroughProperty("btnGetWebs")]
  508.         private Button _btnGetWebs;
  509.         [AccessedThroughProperty("btnSubmit")]
  510.         private Button _btnSubmit;
  511.         [AccessedThroughProperty("chbIncludeDocs")]
  512.         private CheckBox _chbIncludeDocs;
  513.         [AccessedThroughProperty("ddlDestinationWeb")]
  514.         private DropDownList _ddlDestinationWeb;
  515.         [AccessedThroughProperty("ddlLists")]
  516.         private DropDownList _ddlLists;
  517.         [AccessedThroughProperty("ddlSourceWeb")]
  518.         private DropDownList _ddlSourceWeb;
  519.         private const string _defaultText = "";
  520.         private string _text;
  521.         [AccessedThroughProperty("txtList1")]
  522.         private TextBox _txtList1;
  523.         [AccessedThroughProperty("txtList2")]
  524.         private TextBox _txtList2;
  525.         [AccessedThroughProperty("txtMessage")]
  526.         private Label _txtMessage;
  527.         [AccessedThroughProperty("txtWeb1")]
  528.         private TextBox _txtWeb1;
  529.         [AccessedThroughProperty("txtWeb2")]
  530.         private TextBox _txtWeb2;
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>