.CS File
===========================================================
private SPWeb oWeb = null;
protected void Page_Load(object sender, EventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (oWeb = new SPSite(SPContext.Current.Site.Url).OpenWeb())
{
//SPList EventsList = oHomeWeb.Lists["Events"];
SPList oCalendarList = oWeb.Lists.TryGetList("Events");
oWeb.AllowUnsafeUpdates = true;
SPViewCollection collViews = oCalendarList.Views;
bool isTrue = false;
// checking customview is avilable in the list
foreach (SPView view in collViews)
{
if (view.Title.Equals("CustomView"))
{
isTrue = true;
break;
}
}
if (!isTrue) //create a custom view if not avilable in the list
{
string strViewName = "CustomView";
System.Collections.Specialized.StringCollection collViewFields = new System.Collections.Specialized.StringCollection();
collViewFields.Add("LinkTitle");
//collViewFields.Add("Location");
collViewFields.Add("EventDate");
collViewFields.Add("EndDate");
collViewFields.Add("OPSWorkspaceLink");
//string strQuery = "<Where><Gt><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Gt></Where>";
string strQuery = @"
<Where>
<Eq>
<FieldRef Name='WorkspaceLink' />
<Value Type='CrossProjectLink'>1</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name='Modified' Ascending='False' />
</OrderBy>
";
collViews.Add(strViewName, collViewFields, strQuery, 50, true, false);
}
XsltListViewWebPart lvwpShowFiles = new XsltListViewWebPart();
lvwpShowFiles.ID = "wpListView";
lvwpShowFiles.ListName = oCalendarList.ID.ToString("B").ToUpper();
SPView oCustomView = oCalendarList.Views["CustomView"];
lvwpShowFiles.ViewGuid = oCustomView.ID.ToString("B").ToUpper();
dvSummaryView.Controls.Add(lvwpShowFiles);
oWeb.AllowUnsafeUpdates = false;
}
});
}
catch (Exception ex)
{
throw ex;
}
finally
{
oWeb.Dispose();
}
}
.Aspxpage
===========================================================
<div id="dvSummaryView" class="ac-cnt-grey noPad" runat="server"></div>
No comments:
Post a Comment