1).create the folders
2)add items to " Announcement " list.
3)add document file to " ComAnnouncement " library
try
{
SPGroup group1 = SPContext.Current.Web.SiteGroups["AnnouncementGroup"];
if (group1.ContainsCurrentUser)
{
#region [foldercreation,file add to folder]
string strIssueID = txttitle.Text.Trim() + "_Announcement";
hdnUploadPath1.Value = strIssueID.ToString();
{
SPWeb objWeb = SPContext.Current.Web;
SPList DocList = objWeb.Lists.TryGetList("ComAnnouncement");
if (DocList != null)
{
if (DocList.ParentWeb.GetFolder(strIssueID).Exists)
{
}
else
{
SPListItem newfolder = DocList.Items.Add(DocList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, strIssueID);
newfolder["Modified By"] = SPContext.Current.Web.CurrentUser;
newfolder.Update();
objWeb.AllowUnsafeUpdates = true;
if (DocList.ParentWeb.GetFolder(objWeb.Url + "/" + DocList.Title + "/" + strIssueID).Exists)
{
SPFolder IssueFolder = DocList.ParentWeb.GetFolder(objWeb.Url + "/" + DocList.Title + "/" + strIssueID);
SPFolderCollection folders = objWeb.GetFolder(DocList.RootFolder.ServerRelativeUrl).SubFolders;
foreach (SPFolder spfColl in folders)
{
if (spfColl.Name.Equals(newfolder.DisplayName))
{
spfColl.Files.Add(this.FileUpload1.PostedFile.FileName, this.FileUpload1.PostedFile.InputStream);
spfColl.Update();
InsertIems1();
txttitle.Text = string.Empty;
txtbody.Text = string.Empty;
string seldt = Dateofexpire.SelectedDate.ToString();
seldt = string.Empty;
}
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "alert('Details Updated Successfully');window.close();", true);
}
}
else
{
Response.Write("<script>alert(\"success\")</script>");
}
}
#endregion
}
}
catch (Exception ex)
{
Response.Write("<script>alert(\"Failed to announcement Please contact to administrator\")</script>");
// MessageBox.Show("Failed to announcement Please contact to administrator");
}
}
private void InsertIems1()
{
string strIssueID = txttitle.Text.Trim() + "_Announcement";
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Announcement"];
SPListItemCollection coll = list.Items;
SPListItem item = coll.Add();
item["Title"] = txttitle.Text;
item["Body"] = txtbody.Text;
//item["Expires"] = Dateofexpire.SelectedDate;
if (!Dateofexpire.IsDateEmpty)
{
item["Expires"] = Dateofexpire.SelectedDate.ToShortDateString().ToString().Trim();
}
item["AnnouncementTitle"] = FileUpload1.PostedFile.FileName;
item.Update();
}
#endregion
2)add items to " Announcement " list.
3)add document file to " ComAnnouncement " library
try
{
SPGroup group1 = SPContext.Current.Web.SiteGroups["AnnouncementGroup"];
if (group1.ContainsCurrentUser)
{
#region [foldercreation,file add to folder]
string strIssueID = txttitle.Text.Trim() + "_Announcement";
hdnUploadPath1.Value = strIssueID.ToString();
{
SPWeb objWeb = SPContext.Current.Web;
SPList DocList = objWeb.Lists.TryGetList("ComAnnouncement");
if (DocList != null)
{
if (DocList.ParentWeb.GetFolder(strIssueID).Exists)
{
}
else
{
SPListItem newfolder = DocList.Items.Add(DocList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, strIssueID);
newfolder["Modified By"] = SPContext.Current.Web.CurrentUser;
newfolder.Update();
objWeb.AllowUnsafeUpdates = true;
if (DocList.ParentWeb.GetFolder(objWeb.Url + "/" + DocList.Title + "/" + strIssueID).Exists)
{
SPFolder IssueFolder = DocList.ParentWeb.GetFolder(objWeb.Url + "/" + DocList.Title + "/" + strIssueID);
SPFolderCollection folders = objWeb.GetFolder(DocList.RootFolder.ServerRelativeUrl).SubFolders;
foreach (SPFolder spfColl in folders)
{
if (spfColl.Name.Equals(newfolder.DisplayName))
{
spfColl.Files.Add(this.FileUpload1.PostedFile.FileName, this.FileUpload1.PostedFile.InputStream);
spfColl.Update();
InsertIems1();
txttitle.Text = string.Empty;
txtbody.Text = string.Empty;
string seldt = Dateofexpire.SelectedDate.ToString();
seldt = string.Empty;
}
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "alert('Details Updated Successfully');window.close();", true);
}
}
else
{
Response.Write("<script>alert(\"success\")</script>");
}
}
#endregion
}
}
catch (Exception ex)
{
Response.Write("<script>alert(\"Failed to announcement Please contact to administrator\")</script>");
// MessageBox.Show("Failed to announcement Please contact to administrator");
}
}
private void InsertIems1()
{
string strIssueID = txttitle.Text.Trim() + "_Announcement";
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Announcement"];
SPListItemCollection coll = list.Items;
SPListItem item = coll.Add();
item["Title"] = txttitle.Text;
item["Body"] = txtbody.Text;
//item["Expires"] = Dateofexpire.SelectedDate;
if (!Dateofexpire.IsDateEmpty)
{
item["Expires"] = Dateofexpire.SelectedDate.ToShortDateString().ToString().Trim();
}
item["AnnouncementTitle"] = FileUpload1.PostedFile.FileName;
item.Update();
}
#endregion
No comments:
Post a Comment