Cheers
Monday, August 30, 2010
Query to SharePoint database and WSS_Logging Database
While googling for my What's Hot web part I found 2 very good articles which explains why we should not query sharepoint db. And how we can use WSS_Logging db
Monday, August 23, 2010
Monitoring SharePoint Usage through an ASP.NET Web Application
Monitoring SharePoint Usage through an ASP.NET Web Application
By Gayan Peiris
This is very good article for creating an application which can show a desired site usage details
Thursday, August 19, 2010
How to get a month name from date
We can get the month name using following statement
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(datValue.Month)
Cheers..
How to get all available page layouts which can be used to create and page
There was a task in which i had to check what all page layouts are available for a current site which can be used to create a new page. So here is the solution
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
PageLayout[] pageLayouts = pubWeb.GetAvailablePageLayouts();
PageLayout pageLayout = pageLayouts.Where(p => p.Title.Trim() == item["LayoutName"].ToString().Trim()).FirstOrDefault();
if (pageLayout == null)
.......
Cheers....
Check if List or document/Picture library already exists
During one of my project i came accross this situation many time when i had to check whether list or document library already exists or not. So here is the solution
To check document/picture library there is an existing method which can be used like below
if (!web.GetFolder(strName).Exists)
{
......
}
Here 'strName' is the name of document/picture library.
But for list this method does not work. Unfortunately there is no method to check if list exists so we need to do a trick for that, check out below
SPList list = null;
try
{
list = web.Lists[strListTitle];
}
catch { }
if (list == null)
{
.....
Cheers.
Sunday, August 1, 2010
Check if Page is already checked out
It is very helpful while editing the contents of a publishing page to check if desired page is already checked or not.
Here is is the code to check this
Sol 1:
if (pPage.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
pPage.CheckOut();
Sol 2:
SPFile fileSource = web.GetFile(strSourceFilePath);
SPUser user = null;
user = fileSource.CheckedOutBy;
if (user != null)
{....
If we does not check so then we may get error that page is already checked out.
Open a SharePoint popup after server trip
Last day i had a task in which when user clicks a button few pages got created at runtime and after this i had to show the popup window which will show a aspx page having status of all created pages whether successfully created or failed.
Challenge was to open the popup when button click server trip done (Page rerendered).
My method was creating a javascript at run time to open a popup. But issue was when it runs i gets a javascript error.
"Object Doesn't support this property or method"
Issue was my javascript was getting called even before its supporting js files gets load.
After some rnd i found the solution and here it is.
string strScript = "function OpenDialog() { var option = SP.UI.$create_DialogOptions(); option.url = '" + strPath + "'; option.width = 380; option.height = 330; SP.UI.ModalDialog.showModalDialog(option); } ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";
ClientScript.RegisterClientScriptBlock(this.GetType(), "ShowStatusfunction", strScript, true);
Key thing is ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";
What it does is, it will wait untill the specified js gets load then it will call the method
Cheers...
Subscribe to:
Posts (Atom)