sharepoint操作库和栏
一个库有 日期 正文 创建者 修改者 签出对象 5个栏
private static string _webUrl = "";
private static string _domain = "";
private static string _listName = "市局文件、通知栏";
[WebBrowsable(true), Personalizable(false), WebDescription("网站集URL"), WebDisplayName("网站集URL")]
public string SiteUrl
{
get
{ return SPContext.Current.Site.Url; }
}
[WebBrowsable(true), Personalizable(false), WebDescription("网站URL"), WebDisplayName("网站URL")]
public string WebUrl
{
get { return _webUrl; }
set { _webUrl = value; }
}
[WebBrowsable(true), Personalizable(false), WebDescription("域名"), WebDisplayName("域名")]
public string Domain
{
get { return _domain; }
set { _domain = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
public static void ShowMessage(Page page, string message, string target)
{
page.ClientScript.RegisterStartupScript(
page.GetType(),
Guid.NewGuid().ToString(),
string.Format(@"<script language=javascript>alert(""{0}"");window.location.href=""{1}"";</script>",
message.Replace(@"""", "'").Replace("\r\n", @"\n").Replace("\n", @"\n").Replace("\\",
"\\\\").
Replace(@"\\n", @"\n"), target));
}
/// <summary>
/// 保存公告
/// </summary>
/// <returns></returns>
private int SaveNotice()
{
try
{
Guid siteID = SPContext.Current.Site.ID;
SPUser curUser = SPContext.Current.Web.CurrentUser;
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[_listName];
SPListItem item = null;
item = list.Items.Add();
if (string.IsNullOrEmpty(this.txtTitle.Text.Trim()))
{
ShowMessage(this.Page, "请输入标题信息","");
return -1;
}
item["日期"] = this.dtTime.SelectedDate;
item["正文"] = this.txtTestRecord.Html;
item["创建者"] = curUser.LoginName;
item["修改者"] = curUser.LoginName;
item["签出对象"] = curUser.LoginName;
Response.Write(_listName.ToString());
Response.Write(curUser.LoginName.ToString());
item.Update();
}
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
return 1;
}
protected void Button1_Click(object sender, EventArgs e)
{
int id = SaveNotice();
if (id > 0)
{
this.Response.Redirect("11/Forms/AllPages.aspx");
}
}
老报错为 SHAREPOINT\systemMicrosoft.SharePoint.SPException: 若要将项目添加到文档库,请使用 SPFileCollection.Add() 在 Microsoft.SharePoint.SPListItem.PrepareItemForUpdate(Guid newGuidOnAdd, SPWeb web, Boolean bMigration, Boolean& bAdd, Boolean& bPublish, Object& objAttachmentNames, Object& objAttachmentContents, Int32& parentFolderId) 在 Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) 在 Microsoft.SharePoint.SPListItem.Update() 在 sjgg.sjggAdd.SaveNotice()
还有不管ID>0或者小于0都跳转页面