Friday, February 28, 2014

Sharepoint 2013 Visio web access webpart scripts (3. Script to set active to perticular page name(Visio sheet name)

function setPage(callingNode) {
    try {
   

var vwaControl;
vwaControl= new Vwa.VwaControl(getVWAWebPartID1());
   


        // Get id from calling DOM node and set the corresponding page.
        vwaControl.setActivePage(callingNode);
    }
    catch(err) {
        alert(err);
    }
}



// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID1() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

Note: Now when ever we want to set particular page name as active, we will just pass the name of the page(visio page) to that script.
Ex:
onclick= "javascript:setPage('visio page sheet name')");

Monday, February 24, 2014

Sharepoint 2013 Visio web access webpart scripts (2. Script to find list of page names(Visio Sheets names)

<script language="javascript">

// Add a button to display or dismiss the custom message.
document.write("<input type='button' value='Show Message' onclick='onDiagramComplete()' />");

// Hook into the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);

    }
}

// Search SharePoint page to get WebPartID# for Visio Web Access Web Part.
function getVWAWebPartID() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and display message in the Web Part after rendering is complete.
function onDiagramComplete() {
    try{

        // Get references to the current Visio page displayed in the Web Part and the shapes on the page.


 vwaPages = vwaControl.getAllPageIds();
        var pageCount = vwaPages.length;
        var vwaPage = vwaControl.getActivePage();
 for (var i = 0; i < pageCount; i++){
            // Get page ID from array of pages IDs.
            vwaPageId = vwaPages[i];
     
alert(vwaPageId);


//This code returns all the page names
// var vwaPage = vwaControl.getActivePage();
// var vwaPageName = vwaPage.getId();

// alert(vwaPageName);


}




    
    }
    catch(err){
        alert(err);
    }
}

</script>

Sharepoint 2013 Visio web access webpart scripts (1. Script to find active page name(Visio sheet name)




<script language="javascript">

// Add a button to display or dismiss the custom message.
document.write("<input type='button' value='Show Message' onclick='onDiagramComplete()' />");

// Hook into the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);

    }
}

// Search SharePoint page to get WebPartID# for Visio Web Access Web Part.
function getVWAWebPartID() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and display message in the Web Part after rendering is complete.
function onDiagramComplete() {
    try{

      
        var vwaPage = vwaControl.getActivePage();
        var vwaPageName = vwaPage.getId();

alert(vwaPageName);

    
    }
    catch(err){
        alert(err);
    }
}

</script>

script to get current page URL and query string parameters





function getQueryStringParameter(paramToRetrieve) {

var currentPageUrl = "";
if (typeof this.href === "undefined") {
    currentPageUrl = document.location.toString().toLowerCase();
}
else {
    currentPageUrl = this.href.toString().toLowerCase();
}

if (currentPageUrl != null) {
        var params =
       document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    }
    else {
        return "";
    }
  
}

var pagename=getQueryStringParameter('PageName');

Wednesday, December 4, 2013

Code to Get the SharePoint Central administration site UR


Code to Get the SharePoint Central administration site URL:

Add namespace:
using Microsoft.Sharepoint.Administration;

Add below code
 
Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;
          
string webAppUrl = centralWeb.Sites[0].Url;

Tuesday, December 3, 2013

How to access added item values of List Item in ItemAdded event handlers into SharePoint

 
 Code:
 
 
public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            string strTitle = string.Empty;
           using (SPSite site = new SPSite(properties.WebUrl))
           {
           using (SPWeb web = site.OpenWeb())
           {
           SPList list = web.Lists[properties.ListTitle ];
           SPListItem item = list.GetItemByIdSelectedFields(properties.ListItemId, "Title");
           strTitle = (String)item.DisplayName ;
            }
            }
 

Working with BeforeProperties and AfterProperties on SPItemEventReceiver

Here are the results for a list:
List
BeforeProperties
AfterProperties
properties.ListItem
ItemAdding
No value
New value
Null
ItemAdded
No value
New value
New value
ItemUpdating
No value
Changed value
Original value
ItemUpdated
No value
Changed value
Changed value
ItemDeleting
No value
No value
Original value
ItemDeleted
No value
No value
Null
No value means that column value in the hash table was not available. 
New value means that the correct value for the column was available. 
Changed value means that the correct updated value was available.
Original value means that the correct original value was available.
Here is the same test against a document library:
Library
BeforeProperties
AfterProperties
properties.ListItem
ItemAdding
No value
No value
Null
ItemAdded
No value
No value
New value
ItemUpdating
Original value
Changed value
Original value
ItemUpdated
Original value
Changed value
Changed value
ItemDeleting
No value
No value
Original value
ItemDeleted
No value
No value
Null

Properties.ListItem refers the the current value for the list item at that point in the event.  Null means that the item is not available.  My analysis yields the following results:
  • Not surprisingly, we get null values for for ItemAdding (before item is added) and ItemDeleted (after item is deleted). 
  • As correctly documented in the SDK, item events for lists do not expose BeforeProperties.
  • ItemAdding and ItemAdded correctly report the value in the AfterProperties for an list item, but not a library item.  This is curious.