将更新项目保存到splist c#sharepoint [英] save updates items to splist c# sharepoint

查看:97
本文介绍了将更新项目保存到splist c#sharepoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我有想要更新的文本框,到splist,不知道要启动可以帮助我吗?

Hi! i Have textboxes that i want to update , to an splist, dont know were to start can somehelp me?

推荐答案

此代码采用txt框文本并将其保存到SP名单。它创建了一个新的列表项thurhgAddANewSPListItem方法,这是自定义方法但是sharpoint服务提供内置方法,如果项目已经存在则需要获取项目,其余部分与下面相同。你只需要将方法从create更改为get。



我不知道如果这是最好的方式,但它适用于我:P



This code takes txt box texts and saves them into SP list. It creates a new list item thurhg "AddANewSPListItem" method, this is custom method but sharpoint services offer built in methods, if an item allready exists then you need to fetch the item and the rest is the same as below. You just need to change the method from create to get.

I dont know however if this is the best way but it works form me :P

 SPListItem spItem = AddANewSPListItem("ListName");
 spItem["FieldName"] = textBox1.Text.Trim();
 spItem["FieldName2"] = textBox1.Text.Trim();

 //update the item
 using (SPSite site = new SPSite(URLOfYourSharepointSite))
 {
    site.WebApplication.FormDigestSettings.Enabled = false;
    site.AllowUnsafeUpdates = true;
    using (SPWeb currWeb = site.OpenWeb())
    {
      currWeb.AllowUnsafeUpdates = true;
      spItem.Update();
      currWeb.AllowUnsafeUpdates = false;
      site.AllowUnsafeUpdates = false;
      site.WebApplication.FormDigestSettings.Enabled = true;
    }
}





祝你好运!



B



Good luck!

B


这篇关于将更新项目保存到splist c#sharepoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆