programmatically creating the folder inside a sahrepoint list but the name breaks
-
Saturday, April 14, 2012 7:15 PM
i had a typical requirement of creatting sharepoint list items with folders[name of the folder should be a date]
say something like 11-Mar-2012. However, while creating the folder programattically(dd append mm append yy)
the name is appearing broken something like
11-Mar
-2012
However, when i create it manually , it comes fine also the new status shows up..how do i apply that programmatically
All Replies
-
Saturday, April 14, 2012 9:59 PMPlease provide your code. It's a guessing game without seeing the code.
-
Monday, April 16, 2012 9:30 AM
The code snippet is below:
using
(SPSite _site = new SPSite(<url of the site>))
{
using (SPWeb _web = _site.OpenWeb())
{
_web.AllowUnsafeUpdates =
true;
SPList SpList1 = _web.Lists[_list];
#region
DateFolder
string CreateDay=DateTime.Today.Day.ToString();
string CreateMonth=DateTime.Today.Month.ToString();
string CreateYear=DateTime.Today.Year.ToString() ;
string auditFileName = CreateDay + '-' + CreateMonth + '-' + CreateYear;
SPListItem auditFolder =
null;
bool folderExists = false;
for (int i = 0; i < SpList1.Folders.Count; i++)
{
if (SpList1.Folders[i].Folder.Name == auditFileName)
{
auditFolder = SpList1.Folders[i];
folderExists =
true;
}
}
if (!folderExists) // The folder does not exist so we create it and add the item
{
auditFolder = SpList1.Items.Add(SpList1.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, auditFileName);
auditFolder.Update();
}

