/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
protected void Page_Load(object sender, EventArgs e) { // http://www.example.com/page?nid=2 string nid = HttpContext.Current.Request.QueryString["nid"]; if(!string.IsNullOrEmpty(nid)) { using (SPSite site = SPContext.Current.Site) { using (SPWeb web = site.OpenWeb()) { // needed for list item update web.AllowUnsafeUpdates = true; // get list SPList list = web.Lists["ListA"]; // get list item by Id from url SPListItem item = list.GetItemById(Convert.ToInt32(nid)); // create new list item SPListItem itemCopy = list.Items.Add(); // copy attributes itemCopy["Title"] = item.Title; // update db itemCopy.Update(); // set back to default web.AllowUnsafeUpdates = false; } } } }