前台代码
<script type="text/javascript"> function Close() { alert("操作成功") window.location = "http://amid01110/_layouts/15/start.aspx#/Lists/test2/AllItems.aspx"; } </script> <a id="id" name="name">点击</a> <asp:Label ID="Label1" runat="server" Text="请选在推送到的文件路径"></asp:Label> <asp:DropDownList ID="dwlist" runat="server"> </asp:DropDownList> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="推送" />
后台代码:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { InitDropDownList(); } } protected void Button1_Click(object sender, EventArgs e) { /////这个方法只能添加存在的值 using( SPSite site = new SPSite("http://amid01110/")) { SPWeb web = site.RootWeb; string id = Page.Request["ID"]; SPListItem li = web.Lists["test2"].GetItemById(int.Parse(id));//实例化要添加的列的值如果部署到别的列表里就更改test2这个列表名 web.AllowUnsafeUpdates = true;//设置允许更改 //SPList lis = web.Lists["test2"]; //SPListItem ite = lis.Items.Add(); //li["Title"] = li["Title"]; //li["aaa"] = li["aaa"]; //li.Update();//先更新test2 SPList list = web.Lists[dwlist.SelectedItem.Text];//实例化列表名称 SPListItem item = list.Items.Add(); item["Title"] = li["Title"];//向列表添加为Call Tom item["aa"] = li["aaa"];//添加另外一个字段 item["同意"] = li["同意"]; item["时间"] = li["修改时间"]; item["选择用户"] = li["选择用户"]; item.Update();//更新 //web.Dispose(); //site.Dispose(); li.Delete();//删除此项 ClientScriptManager cs = Page.ClientScript; cs.RegisterStartupScript(this.GetType(), "", "<script type=\"text/javascript\">Close() ;</script>"); //调用前台js方法 } } public void InitDropDownList() { using (SPSite site = new SPSite("http://amid01110/")) { ListItemCollection LIColl = new ListItemCollection(); ArrayList list = new ArrayList(); SPWeb web = site.RootWeb; LIColl.Add("wd"); LIColl.Add("test"); LIColl.Add("test2"); //foreach (SPList ls in web.Lists) //{ // //Page.Response.Write(ls.Title + "<br/>");//获取后显示在页面上 // LIColl.Add(ls.Title);//将数据保存list中 //} dwlist.DataSource = LIColl;//绑定 dwlist.DataBind();//绑定 } }