Skip to main content

Use SharePoint Context Menu in Pure Web Application

  1. Include required styles and JavaScript files

<script src="http://catorontdv71/_layouts/1033/owsbrows.js"></script>

<script src="http://catorontdv71/_layouts/1033/ows.js"></script>

<script language='javascript' src='http://catorontdv71/_layouts/1033/ie55up.js'></script>

<script src="http://catorontdv71/_layouts/1033/Menu.js" type="text/JavaScript" language="JavaScript"></script>

<script type="text/JavaScript" language="JavaScript">

<!--

var L_Menu_BaseUrl="http://catorontdv71";

var L_Menu_LCID="1033";

var L_Menu_SiteTheme="";

//-->

</script>

<script>

if (browseris.mac && !browseris.ie5up) {

var ms_maccssfpfixup = "http://catorontdv71/_layouts/1033/styles/owsmac.css";

document.write("<link rel='stylesheet' Type='text/css' href='" + ms_maccssfpfixup + "'>");

}

</script>

<script src="http://catorontdv71/YourApp/JavaScript/YourCustomizedJavascriptfile.js"></script>

<link rel="stylesheet" type="text/css" href="http://catorontdv71/_layouts/1033/styles/ows.css">

<link rel="stylesheet" type="text/css" href="http://catorontdv71/_layouts/1033/styles/menu.css">

<link rel="stylesheet" type="text/css" href="http://catorontdv71/_layouts/1033/styles/sps.css">

<style type="text/css">

.ms-SrvMenuUI { behavior:url("http://catorontdv71/_layouts/1033/Menu.htc"); }

</style>

<style>

v:* { behavior: url(#default#VML) }

o:* { behavior: url(#default#VML) }

.shape { behavior: url(#default#VML) }

</style>

  1. Create your list of items like following sample code: Here, the most important attributes are CTXName and ItemId. You need to create your own context object. This context object will be passed to your customized JavaScript function (see step 3). The ItemId will be assigned to currentItemID global variable, so you can refer it in your custom JavaScript function.

<table ID="Table1">

<tr>

<td class="ms-vb2" height="22">

<table height="100%" cellspacing="0" class="ms-unselectedtitle" onmouseover="OnItem(this);" MsoPnlId="data" CTXName="ctx10001" ItemId="20199" ID="Table2">

<tr>

<td width="100%" class="ms-vb">

<a onfocus="OnLink(this);" onclick="GoToLink(this);return false;" target="_self" href="/clients/FavClientProfile.aspx?ID=20199">ALBERTA NEWSPRINT COMPANY</a>

</td>

<td>

<img src="images/blank.gif" width="13" style="visibility: hidden" alt="">

</td>

</tr>

</table>

</td>

<td class="ms-vb2" height="22">NTT</td>

<td class="ms-vb2" height="22">CIPS</td>

<td class="ms-vb2" height="22">Forest, Paper &amp; Packaging</td>

<td class="ms-vb2" height="22">Edmonton</td>

</tr>

</table>

  1. Create your own JavaScript code and inside it create a function called Custom_AddDocLibMenuItems(m, ctx);

var BASETYPE_PWCCLIENTLIST = 10001;

var BASETYPE_PWCCONTACTLIST = 10002;


var LISTTEMPLATE_PWCMYCLIENT = 10001;

var LISTTEMPLATE_PWCMYENGAGEMENT = 10300;


var CLIENTSTAB = "/Clients/";

var CLIENTSEDITFOLDER = "/Clients/";


var SPSSERVERBASEURL = "http://" + location.hostname;


//For Clients Tab - My List Webpart

ctx = new ContextInfo();

ctx.listBaseType = BASETYPE_PWCCLIENTLIST;

ctx.listTemplate = LISTTEMPLATE_PWCMYCLIENT;

ctx.HttpPath = SPSSERVERBASEURL + CLIENTSTAB;

ctx.HttpRoot = SPSSERVERBASEURL + CLIENTSTAB;

ctx.imagesPath = "/_layouts/images/";

ctx.PortalUrl = "/";

if (ctx.PortalUrl == "") ctx.PortalUrl = null;

ctx.ctxId = 10001;

ctx10001 = ctx;


function Custom_AddDocLibMenuItems(m, ctx)

{

//Available Options: View, Remove from My List

if (ctx.listBaseType == BASETYPE_PWCCLIENTLIST &&

ctx.listTemplate == LISTTEMPLATE_PWCMYCLIENT) // My List

{

strDisplayText = "View Company";

strAction = "STSNavigate('" + SPSSERVERBASEURL

+ CLIENTSTAB + "FavClientProfile.aspx?ID=" + currentItemID

+ "')";

strImagePath = "";

CAMOpt(m, strDisplayText, strAction, strImagePath);


strDisplayText = "Remove from My List";

strAction = "STSNavigate('" + SPSSERVERBASEURL

+ "/_layouts" + CLIENTSEDITFOLDER + "RemoveFavorite.aspx?ID=" + currentItemID

+ "')";

strImagePath = "";

CAMOpt(m, strDisplayText, strAction, strImagePath);


}

}

  1. Screen shot for the result.





Comments

Popular posts from this blog

Manage IIS 7 remotely using PowerShell and AppCmd

We can use  Windows PowerShell remoting features  to manage IIS 7 websites remotely.  Currently, remoting is supported on Windows Vista with Service Pack 1 or later, Windows 7, Windows Server 2008, and Windows Server 2008 Release 2.  Start Windows PowerShell as an administrator by right-clicking the Windows PowerShell shortcut and selecting Run As Administrator .  Enable PowerShell Remoting with Enable-PSRemoting -Force Starting a Remote Session using:  Enter-PSSession -ComputerName <COMPUTER> -Credential <USER> Now the PowerShell connected to the remote server. Any commands issued with work against the remote server. We can use the Appcmd.exe command line tool to manage remote server just as what we do locally. For example, to add an application pool: c:\windows\system32\inetsrv\appcmd add apppool /name:"Contoso" /managedPipelineMode:Integrated /managedRuntimeVersion:"v4.0" /enable32BitAppOnWin64:true To change application p...

Entity framework code first error: OriginalValues cannot be used for entities in the Added state

When I was using Entity framework code first, I encountered an error when I tried to create an entity into database. The entity is: [ Table (" EmployeeProfile ")]     public partial class EmployeeProfile     {         [ Key ]         [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]         public int EmployeeProfileID { get; set; }         [ ForeignKey ("Employee")]         public int EmployeeID { get; set; }         public virtual Employee Employee { get; set; }         [ ForeignKey (" Profile ")]         public int ProfileID { get; set; }         public virtual Profile Profile { get; set; }       ...

X509Certificate2: The system cannot find the file specified.

When I use the new X509Certificate2(fileName, password, X509KeyStorageFlags.DefaultKeySet) to create certificate from certificate file containing private key in my web application, I got following error message: System . Security . Cryptography . CryptographicException : The system cannot find the file specified . at System . Security . Cryptography . CryptographicException . ThrowCryptogaphicException ( Int32 hr ) at System . Security . Cryptography . X509Certificates . X509Utils . _LoadCertFromBlob ( Byte [] rawData , IntPtr password , UInt32 dwFlags , Boolean persistKeySet , SafeCertContextHandle & pCertCtx ) at System . Security . Cryptography . X509Certificates . X509Certificate . LoadCertificateFromBlob ( Byte [] rawData , Object password , X509KeyStorageFlags keyStorageFlags ) at System . Security . Cryptography . X509Certificates . X509Certificate2 .. ctor ( Byte [] rawData , String password , X509KeyStorageFlags keyStorageFlags ) In orde...