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 !!!

Sunday, May 27, 2012

The report parameter is read only and cannot be modified

Hi All,

We have a main report which has 5 subreports in it. We are passing the parameter value from main report to sub report. All subreports works fine but when we try to run the main report, we got the following error:
                           
"The report parameter is read only and cannot be modified."


Resolution:

To resolve the above error, just follow the below steps:
a. Open the Sub Report in Design View
b. Click on Report Properties tab under Reports as shown





c. Select the parameter which is throwing the error. In my case, the parameter "language" was causing the
    problem.
d. Under properties for the parameter, select the "Multi-value" option for the parameter as shown below



















e. Once this is done, just run the main report and was able to render the report without any problem in BIDS.
f. Now, upload the reports in Reports Library
g. Click on the report and select "Manage Parameters"

























h.This will display all the parameters available for a particular report as shown below






i. Make sure that the Language parameter is set to Hidden. The problem was that if the parameter is set to internal, we get the exception that the parameter is read-only and cannot be modified.
j. Once this is done, we are able to render the reports in SharePoint without any problem.

Thanks.