sharepoint操作库和栏

chu715322834 2011-04-17 10:46:13
一个库有 日期 正文 创建者 修改者 签出对象 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都跳转页面
...全文
96 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Justin-Liu 2011-04-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yun_liang1028 的回复:]
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsiteSrc = oSiteCollection.AllWebs["Source_Site_Name"];
SPWebCollection collWebsites =
oSiteCollection.AllWebs["Destination_Site_Name"].……
[/Quote]
bingo
chu715322834 2011-04-17
  • 打赏
  • 举报
回复
对文档库 操作 要怎么写
Oo云 2011-04-17
  • 打赏
  • 举报
回复
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsiteSrc = oSiteCollection.AllWebs["Source_Site_Name"];
SPWebCollection collWebsites =
oSiteCollection.AllWebs["Destination_Site_Name"].Webs;

SPFile oFile = oWebsiteSrc.GetFile("Source_Folder_Name/Source_File");
string strFilename = oFile.Name;
byte[] binFile = oFile.OpenBinary();

foreach (SPWeb oWebsite in collWebsites)
{
if (oWebsite.GetFolder("Shared Documents").Exists)
{
SPFolder oFolder = oWebsite.GetFolder("Shared Documents");
oFolder.Files.Add(strFilename, binFile, true);
}
oWebsite.Dispose();
}
oWebsiteSrc.Dispose();

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧