SPWebApplication spwebApplication = null ;
SPWeb web = null;
SPSecurity.RunWithElevatedPrivileges(delegate
{
string newSiteUrl = string.Empty;
try
{
using (SPSite spSite = new SPSite(GetSharepointURL()))
{
spwebApplication = spSite.WebApplication;
if (spwebApplication != null)
{
//FormDigestSettings to disable security validation settings for this code only.
spwebApplication.FormDigestSettings.Enabled = false;
var siteCollections = spwebApplication.Sites;
if (siteCollections != null)
using (SPSite newSite = siteCollections.Add(string.Format("Sites/{0}", journalId), shortname, journalname, 1033, "STS#1"
, Frontiers.Configuration.ConfigurationManager.AppSettings["SiteCollectionOwner"], Frontiers.Configuration.ConfigurationManager.AppSettings["SiteCollectionOwnerName"], string.Empty))
{
newSiteUrl = newSite.Url;
if (newSite.AllWebs.Count > 0)
{
web = newSite.AllWebs[0];
if (web != null)
{
web.AllowUnsafeUpdates = true;
Guid id = web.Lists.Add("Articles Library", "Articles Library", SPListTemplateType.DocumentLibrary);
// web.Lists.U
if (id != null)
{
web.Update();
SPList list = web.Lists[id];
list.EnableVersioning = true;
list.OnQuickLaunch = true;
list.Fields.Add("DocumentType", SPFieldType.Text, false);
SetFieldProperties(list.Fields["DocumentType"]);
list.Fields.Add("FileFormat", SPFieldType.Text, false);
SetFieldProperties(list.Fields["FileFormat"]);
list.Fields.Add("DocumentId", SPFieldType.Text, false);
SetFieldProperties(list.Fields["DocumentId"]);
list.Fields.Add("TitleName", SPFieldType.Text, false);
SetFieldProperties(list.Fields["TitleName"]);
list.Fields.Add("StageName", SPFieldType.Text, false);
SetFieldProperties(list.Fields["StageName"]);
list.Fields.Add("IsDeleted", SPFieldType.Boolean, false);
SetFieldProperties(list.Fields["IsDeleted"]);
list.Fields["IsDeleted"].DefaultValue = "0";
list.Fields["IsDeleted"].Update();
list.Fields.Add("Checked Out To", SPFieldType.User, false);
SetFieldProperties(list.Fields["Checked Out To"]);
// list.Fields[0].ShowInDisplayForm
SPView defaultView = list.DefaultView;
defaultView.ViewFields.Add("DocumentType");
defaultView.ViewFields.Add("FileFormat");
defaultView.ViewFields.Add("DocumentId");
defaultView.ViewFields.Add("TitleName");
defaultView.ViewFields.Add("StageName");
defaultView.ViewFields.Add("IsDeleted");
defaultView.ViewFields.Add("Checked Out To");
defaultView.Update();
list.Update();
}
}
}
flag = true;
}
}
}
}});