Tuesday, November 6, 2012

WebPart Maintenance Page in SharePoint

Hi All,

WebPart Maintenance page is used to close Web Parts on your page, restore defaults to Web Parts, or delete Web Parts from your page.

To go to this page, just type contents=1 in query string.

Example: http://sp2007/default.aspx?contents=1

WebPart Maintenance Page screen:












We can close, delete the webparts by just selecting them using checkbox.

Thank you !

Wednesday, September 5, 2012

Cannot make a cache safe URL for "styles/~/SampleProject/StyleSheet.css", file not found. Please verify that the file exists under the layouts directory.

Hi All,

While trying to register a CSS file in SharePoint using CSSRegistration class as:

// Register CSS File
CssRegistration.Register("~/_layouts/SampleProject/StyleSheet.css");

We got the following error:

"Cannot make a cache safe URL for "styles/~/SampleProject/StyleSheet.css", file not found. Please verify that the file exists under the layouts directory".






One of the benefits of using SharePoint:CSSRegistration is that it prevents multiple loading of same CSS file. For Example, if we try to register a CSS file multiple times as:


// Register CSS File
 CssRegistration.Register("/_layouts/SampleProject/StyleSheet.css");
 CssRegistration.Register("/_layouts/SampleProject/StyleSheet.css");
 CssRegistration.Register("/_layouts/SampleProject/StyleSheet.css");
 CssRegistration.Register("/_layouts/SampleProject/StyleSheet.css");

The final rendered Page will have only one instance of this style sheet.

Ok. Coming back to the problem, the Resolution is to remove ~ in the URL. Hence, the correct statement would be:


// Register CSS File
 CssRegistration.Register("/_layouts/SampleProject/StyleSheet.css");

Here is a good source to know more about SharePoint:CSSRegistration:
http://tommdaly.wordpress.com/2012/05/02/sharepoint-cssregistration-or-link/

Thanks !

Thursday, August 30, 2012

Telerik Tree to Add, Edit, Delete, Move Up and Move Down Nodes

Hi All,

We had a requirement to have a Telerik Tree to perform the below operations on Nodes:

a. Add a Node
b. Edit a Node
c. Delete a Node
d. Move Up a Node
e. Move Down a Node
f. Drag and Drop Nodes with in Tree

We will be having XML in a separate XML file (TelerikTreeXML.xml). Below is the mock up of how it looks:

<?xml version='1.0' encoding='utf-8'?>
<Tree>
  <Node Text='ParentNode1' Expanded='False'></Node>
  <Node Text='ParentNode2' Expanded='False'></Node>
  <Node Text='ParentNode3' Expanded='False'></Node>
  <Node Text='ParentNode4' Expanded='False'></Node>
  <Node Text='ParentNode5' Expanded='False'></Node>
</Tree>

We need to load this XML content from TelerikTreeXML.xml file and bind it to the Tree as shown below:


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadTreeView.LoadContentFile("~/XML/XMLFile.xml");
    }
}

We have a context menu which will be displayed on right click of a node as shown in below image:


















Below is the code to display context menu (Javascript)

function setMenuItemsState(menuItems, treeNode) {
    for (var i = 0; i < menuItems.get_count(); i++) {
        var menuItem = menuItems.getItem(i);
        switch (menuItem.get_value()) {
            case "1":
                formatMenuItem(menuItem, treeNode, 'Add');
                break;
            case "2":
                formatMenuItem(menuItem, treeNode, 'Edit');
                if (treeNode.get_level() == 0) {
                    menuItem.set_enabled(false);
                }
                break;
            case "3":
                formatMenuItem(menuItem, treeNode, 'Delete');
                if (treeNode.get_level() == 0) {
                    menuItem.set_enabled(false);
                }
                break;
            case "4":
                formatMenuItem(menuItem, treeNode, 'Move Up');
                if (treeNode.get_isFirst() == true || treeNode.get_level() == 0) {
                    menuItem.set_enabled(false);
                }

                break;
            case "5":
                formatMenuItem(menuItem, treeNode, 'Move Down');
                if (treeNode.get_isLast() == true || treeNode.get_level() == 0) {
                    menuItem.set_enabled(false);
                }
        }
    }
}


and here is the code for formatMenuItem function:

function formatMenuItem(menuItem, treeNode, formatString) {
    var nodeValue = treeNode.get_value();
    if (nodeValue && nodeValue.indexOf("_Private_") == 0) {
        menuItem.set_enabled(false);
    }
    else {
        menuItem.set_enabled(true);
    }
}

The operations supported for each and every node depends on the type of node selected. For Example, if the node is Parent Node (that is at first level), then only "Add" operation is supported. Add operation will add child nodes to the selected node. Similarly, if there is only one child for a particular node, then "Move Up" and "Move Down" operations will be disabled. The Enabling/Disabling of node will be taken care by formatMenuItem function.

The below is the code for Telerik:RadTreeView









The below is the link for code used to implement this Tree. Note that this is rough piece of code and is not formatted/optimized. Use it at your own risk.

https://skydrive.live.com/redir?resid=D6A20558D41A4EB9!5260

Enjoy and let me know your comments. Have a great day !!!