protected void submit_click(object sender, EventArgs
e)
{
using (SPSite site = SPContext.Current.Site)
{
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
bool isFolderExist = false;
DateTime dt = DateTime.Now;
SPListItem folderColl_item;
SPListItemCollection folderColl;
SPList list = web.Lists["ListName"];
folderColl = list.Folders;
foreach (SPListItem
splistitem in list.Folders)
{
SPFolder folder = splistitem.Folder;
if
(folder.Name.Equals(dt.Year.ToString()))
{
isFolderExist = true;
}
}
if
(!isFolderExist)
{
folderColl_item = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder,
dt.Year.ToString());
folderColl_item.Update();
list.Update();
}
folderColl = list.Folders;
foreach (SPListItem
splistitem in list.Folders)
{
SPFolder folder = splistitem.Folder;
if
(folder.Name.Equals(dt.Year.ToString()))
{
SPListItemCollection itemColl = list.Items;
SPListItem item = itemColl.Add(folder.ServerRelativeUrl, SPFileSystemObjectType.File, null);
item["test"] = "test";
item.Update();
list.Update();
}
}
web.AllowUnsafeUpdates = false;
}
}
No comments:
Post a Comment