Showing posts with label List Views. Show all posts
Showing posts with label List Views. Show all posts

Tuesday, August 28, 2012

From the depths of SharePoint's sp.js Pt. 2

So I lied... :)  The function found below is a part of core.js.

A good ol' fashioned
console.dir( GetCurrentCtx().clvp );
generates this bit of awesome:

{

 ctx : [object Object],

 tab : [object],

 pagingTab : null,

 tBody : null,

 wpq : "WebPartWPQ4",

 inplUrl : "http://portal/SPDev/_layouts/inplview.aspx?List={49AFC299-FC30-4EE9-9571-50B3B366969E}&View={876230CC-BE1A-4845-8998-652BB77C891C}&ViewCount=7&ListViewPageUrl=http://portal/SPDev/pages/spUtils.aspx&IsXslView=TRUE",

 trEmpty : null,

 rootFolder : null,

 rootFolderGuid : null,

 rgpag : null,

 wpid : null,

 isEditing : false,

 dsrc : null,

 isInserting : false,

 strGroupName : null,

 strGroupCache : null,

 bRequestOutstanding : false,

 isEcbInfo : false,

 queueEcbInfo : ,

 fnEcbCallback : null,

 rgpaging : ,

 focusInfo : null,

 CUIItemInfo : [object Object],

 Init : function CLVPInit(){ULSiIp:;var f=this.ctx.listBaseType==1,d;if(this.ctx.listTemplate=="109"){this.ctx.clvp=null;return}d=this.ctx.listName+"-"+this.ctx.view;var b=GetElementsByName(d);if(b.length==0&&f){d="onetidDoclibViewTbl0";b=GetElementsByName(d)}va,

 RestoreNavigation : function CLVPRestoreNavigation(){ULSiIp:;var a=window.location.hash,c=this.InplViewUrl(),b=this.RefreshCurrent(true);b=b.substr(c.length+1);if(a.indexOf("InplviewHash=")==1){a=DecodeHashAsQueryString(a);var d=a.substr(14,38);if(d!=this.ctx.view)return;a=,

 FindWebPartDiv : function CLVPFindWebPartDiv(b){ULSiIp:;var a=b;while(a!=null&&a.tagName!="DIV")a=a.parentNode;return a},

 SyncPagingTables : function CLVPSyncPagingTables(){ULSiIp:;var b=this.pagingTab,a=document.getElementById("topPagingCell"+this.wpq.substr(7));if(b==null){if(a!=null)a.style.display="none";return}if(a!=null){a.style.display="";if(GetInnerText(a)!=GetInnerText(b))a.innerHTML,

 RehookPaging : function CLVPRehookPaging(){ULSiIp:;if(typeof this.ctx.noAJAX!="undefined"&&this.ctx.noAJAX)return;var tab=this.pagingTab;if(tab==null){this.SyncPagingTables();return}for(var lnks=tab.getElementsByTagName("A"),i=0;i<lnks.length;i++){var lnk=lnks[i],str=",

 FilterString : function CLVPFilterString(){ULSiIp:;if(this.rgpaging==null)return null;var a,d,b=[],c=true;for(a in this.rgpaging)if(a.indexOf("Filter")==0||a.indexOf("Sort")==0){if(c)c=false;else b.push("&");b.push(a);b.push("=");b.push(this.rgpaging[a])}return b.join(,

 RefreshPaging : function CLVPRefreshPaging(c,a,b){ULSiIp:;if(a!=null)this.tBody=document.getElementById(a);var d=this.isEditing?"JsGrid":null;return this.RefreshPagingEx(c,true,d,b)},

 RefreshPagingEx : function CLVPRefreshPagingEx(e,q,p,t){ULSiIp:;var s=GetUrlKeyValue("PageFirstRow",false,e)=="1";if(s)e=RemoveOnlyPagingArgs(e);var v=new CUrl(e),h=v.query;if(h.length>0)h=h.substr(1);var i=h.split("&"),f,a=[];if(p!=null)a.push("&Cmd="+p);else this.isEdit,

 ResetSelection : function CLVPResetSelection(){ULSiIp:;var a=this.ctx,f=true;this.CUIItemInfo=null;if(CountSelectedItems(a)>0){var h=a.dictSel;a.dictSel=[];a.CurrentSelectedItems=0;var g=window.location.href;if(g.indexOf("Filter")==-1&&g.indexOf("Sort")==-1){var d=this.t,

 WebPartId : function CLVPWebPartId(){ULSiIp:;if(this.wpid==null){if(this.tab!=null){var a=this.tab;a=GetAncestor(a,"DIV");if(a!=null){if(a.getAttribute("WebPartID2")!=null){this.wpid=a.getAttribute("WebPartID2");return this.wpid}if(a.getAttribute("WebPartID")!=null),

 RefreshCore : function CLVPRefreshCore(strUrl){ULSiIp:;MenuHtc_hide();var req;if(window.XMLHttpRequest)req=new XMLHttpRequest;else req=new ActiveXObject("Microsoft.XMLHTTP");var additionalPostData="";if(typeof this.ctx.overrideSelectCommand!="undefined"){additionalPos,

 RefreshCurrent : function CLVPRefreshCurrent(){ULSiIp:;var a=document.URL;STSNavigate(a)},

 GetQueryString : function CLVPGetQueryString(){ULSiIp:;if(this.tab!=null&&this.tab.getAttribute("FilterLink")!=null)return this.tab.getAttribute("FilterLink");else return document.URL},

 RefreshEcbInfo : function CLVPRefreshEcbInfo(b){ULSiIp:;var a=this.GetQueryString();a=FixUrlFromClvp2(this,a,false);this.isEcbInfo=true;this.strGroupName=b;var c=this;this.RefreshPagingEx(a,false,"EcbView")},

 CacheEcbInfo : function CLVPCacheEcbInfo(b){ULSiIp:;if(this.ctx.HasRelatedCascadeLists==1&&this.ctx.CascadeDeleteWarningMessage==null){var j="<CascadeDeleteWarningMessage>",k="</CascadeDeleteWarningMessage>";if(b.startsWith(j)){var g=b.indexOf(k);if(g!==-1){this.ctx.Ca,

 EnsureEcbInfo : function CLVPEnsureEcbInfo(c,f,a){ULSiIp:;var g="ecbtab_ctx"+this.ctx.ctxId,b=document.getElementById(g);if(b==null&&this.tab!=null&&this.tab.parentNode==null)for(var d=0;d<this.tab.childNodes.length;d++){var e=this.tab.childNodes[d];if(e.id==g)b=e}if(b&,

 InvalidateEcbInfo : function CLVPInvalidateEcbInfo(){ULSiIp:;var b="ecbtab_ctx"+this.ctx.ctxId,a=document.getElementById(b);if(a!=null){this.tab.removeChild(a);this.DeleteGroupNameCache()}},

 GetEcbInfo : function CLVPGetEcbInfo(b){ULSiIp:;var a=this.EnsureEcbInfo();if(a!=null)if(a.dict!=null)return a.dict[b];return null},

 SwitchToEdit : function CLVPSwitchToEdit(){ULSiIp:;var a=document.URL;a=FixUrlFromClvp2(this,a,false);this.RefreshPagingEx(a,false,"JsGrid")},

 EnsureChangeContext : function CLVPEnsureChangeContext(){ULSiIp:;if(this.cctx==null)this.cctx=new SP.ClientContext(null)},

 DeleteItemCore : function CLVPDeleteItemCore(c,f){ULSiIp:;var h=this.ctx.listBaseType==1;this.EnsureChangeContext();var a=null;if(typeof this.rgehs=="undefined")this.rgehs=[];var b,e;b=new SP.ExceptionHandlingScope(this.cctx);this.rgehs.push(b);e=b.startScope();this.cctx,

 CheckoutItem : function CLVPCheckoutItem(f,d){ULSiIp:;this.EnsureChangeContext();if(typeof this.rgehs=="undefined")this.rgehs=[];var a,c,b=null;if(d!=0)return;a=new SP.ExceptionHandlingScope(this.cctx);this.rgehs.push(a);c=a.startScope();b=this.cctx.get_web().get_lists,

 DiscardCheckoutItem : function CLVPDiscardCheckoutItem(e,g){ULSiIp:;this.EnsureChangeContext();if(typeof this.rgehs=="undefined")this.rgehs=[];var b=null,a,f;if(g!=0)return;a=new SP.ExceptionHandlingScope(this.cctx);this.rgehs.push(a);f=a.startScope();b=this.cctx.get_web().ge,

 CheckinItem : function CLVPCheckinItem(g,j,a){ULSiIp:;this.EnsureChangeContext();if(typeof this.rgehs=="undefined")this.rgehs=[];var c=null,b,h;if(j!=0)return;b=new SP.ExceptionHandlingScope(this.cctx);this.rgehs.push(b);h=b.startScope();c=this.cctx.get_web().get_list,

 ManageCopies : function CLVPManageCopies(f,e){ULSiIp:;if(e!=0)return;var b=this.GetEcbInfo(f);if(b!=null&&b.getAttribute("Url")!=null){var d=this.ctx.HttpRoot+"/_layouts/managecopies.aspx?ItemUrl="+b.getAttribute("Url")+"&Source="+GetSource(),a=window["ctx"+this.ctx.ct,

 ShowErrorDialog : function CLVPShowErrorDialog(g){ULSiIp:;var i,a=[],d=null,c=false;for(i in this.rgehs){var b=this.rgehs[i];if(b.get_hasException()){var f="s4-dlg-err-itm";if(!c){f="s4-dlg-err-firstitm";c=true;a.push(SP.Res.dlgTitleError)}var k=b.get_errorMessage();a.pus,

 InplViewUrl : function CLVPInplViewUrl(){ULSiIp:;if(this.inplUrl!=null)return this.inplUrl;var a=[],b=escapeUrlForCallback(this.ctx.HttpRoot);a.push(b);b[b.length-1]!="/"&&a.push("/");a.push("_layouts/inplview.aspx?List=");a.push(this.ctx.listName);if(this.ctx.view!=n,

 InplViewUrlTrim : function CLVPInplViewUrlTrim(a){ULSiIp:;var b="";if(a)if(typeof this.ctx.overrideFilterQstring!="undefined")b=a.substr(this.InplViewUrl().length-this.ctx.overrideFilterQstring.length);else b=a.substr(this.InplViewUrl().length+1);return b},

 ShowPopup : function CLVPShowPopup(a){ULSiIp:;MenuHtc_hide();if(typeof this.fnOnCommitPopup!="undefined"&&this.fnOnCommitPopup!=null)OpenPopUpPage(a,this.fnOnCommitPopup);else OpenPopUpPage(a,RefreshPage);return false},

 ValidateField : function CLVPValidateField(e,d,a,b){ULSiIp:;var c=this.FieldCommand("FldValidate",e,d,a,b),f={callback:a,newval:b,strCmd:c};if(this.qvalidate==null)this.qvalidate=[];this.qvalidate.push(f);if(!this.isValidating){this.isValidating=true;this.RefreshCore(c),

 FieldCommand : function CLVPFieldCommand(j,h,d,m,f){ULSiIp:;var a=[];a.push(this.InplViewUrl());a.push("&Cmd=");a.push(j);a.push("&Field=");a.push(d);a.push("&FieldValue=");var b=h.GetProp(d),c,n=this.gridParam.tableViewParams.columns.GetColumnByKey(d),k=jsGridParams.t,

 IsInGroupCache : function CLVPIsInGroupCache(a){ULSiIp:;if(this.strGroupCache==null)return false;return this.strGroupCache.indexOf(a+"$")!=-1},

 CacheGroupName : function CLVPCacheGroupName(a){ULSiIp:;if(this.strGroupCache==null)this.strGroupCache=a+"$";else this.strGroupCache=this.strGroupCache+a+"$"},

 DeleteGroupNameCache : function CLVPDeleteGroupNameCache(){ULSiIp:;if(this.strGroupCache==null)return;var b=0,a;a=this.strGroupCache.indexOf("$",b);while(a!=-1){var d=this.strGroupCache.substring(b,a),e="ecbtab_ctx"+this.ctx.ctxId+"_"+d,c=document.getElementById(e);c&&this.tab,

 EnqueueEcbInfoRequest : function CLVPEnqueueEcbInfoRequest(b){ULSiIp:;for(var a=0;a<this.queueEcbInfo.length;a++)if(this.queueEcbInfo[a]==b)return;this.queueEcbInfo.push(b)},

 NoOutstandingECBRequests : function CLVPNoOutstandingECBRequests(){ULSiIp:;if(this.isEcbInfo)return false;if(this.queueEcbInfo.length>0)return false;return true}

}

That makes a bunch of noise, however, you'll see an interesting URL at the property named: inplUrl. 
Upon visiting this URL, you'll see all of your data for that particular view.  This seems very attractive for AJAX applications in SharePoint.  Look for more to come in regards to this...

Cheers,
Matthew

Tuesday, February 15, 2011

Redirect calendar view Web Parts to any date and any view

This only works for WSS 3.0 and MOSS 2007.  2010 works completely different.

There was an interesting email I received in my inbox the other day.  It came from @KerriAbraham and said: How can I display next week on a weekly calendar view?  I must be missing something obvious.

With an email like this, I always refer that person to a forum.  If it’s worth asking, then it’s worth sharing…  Here’s a link to the post: http://endusersharepoint.com/STP/viewtopic.php?f=10&t=2835

Looking at an OOTB calendar view, I noticed when changing the dates and views from day, week, and month; the URL updated with new query strings.  These query strings are CalendarPeriod & CalendarDate.

CalendarPeriod

This parameter (query string) accepts 3 different values.  Each of these are valid and produce different views for the calendar.

  1. CalendarPeriod=day
  2. CalendarPeriod=week
  3. CalendarPeriod=month

When this parameter is set, the calendar will automatically update to day, week, or month.

CalendarDate

This parameter works a little different, but still follows a consistent pattern.  This parameter accepts a date. (I’m captain obvious, I know…)  The format of the date should be:

M/DD/YYYY

Since we can’t literally put “/” in a parameter and expect it to work, we need to encode those values.  With that in mind “/” turns into “%2F”.  So our parameter’s value really looks like this:

2%2F15%2F2011

URL with parameters set

Now let’s look at what the URL actually will look like if we wanted to do a view based on the week and the day of Feb. 20, 2011.

CalendarQueryString

You are probably thinking right now…  I knew all of this stuff, did I really just waste 2 minutes reading this post?  Absolutely not… You need to know all of this stuff and a reiteration of the basics will help you understand the script below. 

RedirectCalendar.js

This script is based off of Christophe Humbert’s redirect script in the SharePoint User’s Toolkit.  There are lots of excellent scripts stored here that will change how you use SharePoint.  Also, this post is a great example of it, do not take solutions you find on the internet for face value.  With that in mind, let’s get on with it…

URL="http://URL/Calendar/WebPartPage.aspx",redirectDay=5,popup="You will be redirected automatically.";
var d=new Date();
var currDay = d.getDay();
var currMonth = d.getMonth();
var currYear = d.getFullYear();
currMonth++;
// Calculate day to redirect to
var redirectToDay = d.getDate() + 7;

/*
Sets query string for redirect.
To redirect to Month view; Change CalendarPeriod to month.
*** ?CalendarPeriod=month ***
To redirect to Day view; Change CalendarPeriod to equal
*** ?CalendarPeriod=day ***
*/
qString = "?CalendarPeriod=week&CalendarDate="+currMonth+"%2F"+redirectToDay+"%2F"+ currYear;

function Redirect() {
// Look for existing query strings. If found, do nothing.
if (window.location.href.indexOf("?CalendarPeriod") >= 0 || window.location.href.indexOf("&CalendarDate") >= 0) {
return false;
} else {
if ((!(currDay == redirectDay))) {
return false;
} else {
if (popup) { alert(popup); }
window.location.href=URL+qString;
}
}
}
Redirect();


This script allows you to set your variables without much trouble.  The variables that you should be concerned with are:




  • URL


  • redirectDay


  • popup


  • redirectToDay



The URL needs to be set to the page where your calendar view exists.



CalendarCurrentURL



The redirectDay is used for what day you’d like for the redirect to occur.  Sunday = 0; Saturday = 6.  This script is locked and loaded for Friday.



popup is used for alerting the user redirection is about to happen.  If you don’t like this, then set popup=””.  That will make popup equal false under the hood and not bug you.



The last variable is redirectToDay.  If you look at the code, you’ll notice this variable is being set based off of the current date.  Kerri wanted to add 7 days to the redirect on Friday.  That’s why you see:



var redirectToDay = d.getDate() + 7;


Feel free to add however many days you’d like to this date.  After you’ve changed all of your variables, you’ll notice when you visit this page on the day you’ve configured, the redirect will automatically happen.  Hope you like…

Thursday, October 21, 2010

SharePoint: Integrate ASP.net controls with Forms – Pt4: Trimming Drop Down List results using CAML

Pt.1: Use an SP Datasource to push values to a drop-down menu control
Pt2: Adding a DVWP Form to the page
Pt3: Update the DVWP Form using a Drop-Down
Pt4: Trimming Drop Down List results using CAML
Part 5: Force Selection within Drop Down List
Pt6: Bonus: Embed documents to page

ACK!!! CODE!!!

I’ve been writing these posts by using a *real* no code approach, sort of.  I have a very different view of what no code means, but that’s a different story altogether.  However, this article I’d like to have you peer into the dark-side.  I know all too well myself, viewing code can make your eyes bug out, but I do feel it’s necessary at some point to learn.  I’ve taught myself most of the programming skills I possess today, so I know you can too.  I understand trying to learn these languages on your own can be a real burden, so if you don’t understand how it works, just try it anyway.  The worst that will happen is the solution will not work.  There’s no shame in trying and if it does work, then you can impress your boss!

DVWP & CAML

We should probably look at how these two are related.  CAML (Collaborative Application Markup Language) queries are the instructions within the DVWP or SPDatasource that controls what data is retrieved from the database.  The CAML query is hidden from you unless you know what you are looking for.  Here’s a sample line of code that contains a CAML query:
<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;/View&gt;" UseInternalName="True" ID="dataformwebpart2">
Within this line of code is a SelectCommand.  This command combined with the CAML: "&lt;View&gt;&lt;/View&gt;" will control what information is displayed to us in the browser.  I wont get into all of the details here, but I thought it would be important to show you what’s happening under the hood.

Okay CAML, I sort of get it.  Now what?

What we want to do is trim the results of the Drop Down List to only show what items have been created by the currently logged in user.  To do that, we need to update the SelectCommand for our SPDatasource with our own CAML.  What I like to do is search for the SelectCommand by clicking into the Code View window, and then clicking on Edit, Find.  Remember to click into the code view at the top of the page.
image image
If you’ve followed along from Step 1, then the first SelectCommand that you’ll find is the one we’ll need to update.  The code should look similar to this:
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;/View&gt;" id="spdatasource1">
<SelectParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</InsertParameters>
</SharePoint:SPDataSource>
We’ll need to only update the SelectCommand with our custom CAML query:
&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;Author&quot;/&gt;&lt;Value Type=&quot;Integer&quot;&gt;&lt;UserID/&gt;&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;
The final result should look similar to this:
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;Author&quot;/&gt;&lt;Value Type=&quot;Integer&quot;&gt;&lt;UserID/&gt;&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" id="spdatasource1">
<SelectParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ListID" DefaultValue="{D3CB17ED-B351-4463-94E5-9C4863A3CEA3}"/>
</InsertParameters>
</SharePoint:SPDataSource>
Now would be a good time to save your work!  When we view the page now, all you will see in the Drop Down is the documents you’ve created.  When a different user views this page, the same will hold true.  They’ll only view the documents that they’ve created.  With this tiny piece of CAML, you can see how easy it can be to change the interaction within the page.  Don’t lock yourself into a box either, CAML will allow you to filter anything within the list.  So, if I wanted to, I could change the CAML to retrieve the only the documents I’ve created and also  if the DocCategory equals: I’ve been slacking.  Try to be as creative as you can, I think you’ll be impressed with what you can do with this.

CAML is tough to learn.  Is there an easier way?

Absolutely!  There are several ways of learning CAML.  First you *could* decipher the official documentation for CAML on MSDN or you can try out these 2 different approaches.  First up is to crack open your Document Library and create a view.  Let’s filter this library for all Docs created by [Me] AND when the DocCategory equals: I’ve been slacking.
image
Once you’ve created this view, you’ll notice in SPD, the view appears as an .aspx page.  If it doesn’t, refresh SPD by pressing F5 and it’ll be there.
image
We need to open this page and convert this Web Part into an XSLT View.  I do that by right clicking on the Web Part and selecting; you guessed it: Convert To XSLT Data View.  Once this has been converted, we can search through the code for our SelectCommand.  Yep, we just used SharePoint Designer as a CAML code generator.  Pretty cool eh?  I use this approach when I know my filters are going to be more complex than normal.  I can take it as far as I can before I have to tweak it manually.  So that’s one way to start learning CAML. 
Next up is to use the free CAML Builders that are on the internet.  These two are the best I’ve found: U2U CAML Query Builder & Stramit CAML Viewer.  These work a little differently than the first method, but you can build your code all the same.  I suggest downloading both of them and experimenting with the capabilities of both.  I’m still learning the nuances of CAML myself, so I always use these different methods to generate my code.  Once you’ve generated the code, learning the language will take you to the next level and allow you to produce some very cool results. 
You’ll also notice when you use these two tools, the code is in this format:
<View>
<Query>
<Where>
<Eq>
<FieldRef Name="Author"/>
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
</Where>
</Query>
</View>
You’ll need to escape this code in order to work well with your DVWP or SPDatasource.  I’ve wrote a PowerShell script to do just that or you can use the XML Escape Tool.  Both of these will convert all of the characters that aren’t allowed in the SelectCommand into characters that are allowed.  I’ve listed them below for you:


Original Character

Escaped


&apos;


&quot;

&

&amp;

<

&lt;

>

&gt;
Note: The CAML query cannot contain any white space.  The code must also be in one continuous line. It sounds like a lot of steps, but once you get the hang of it, you’ll be flying through this stuff.   Post a comment and let me know which method you like the best.

What’s next?

This article wasn’t supposed to be this long, but in the end, I felt it was necessary.  Hopefully it was clear enough to follow.  There’s still one more tweak I’d like to show you.  With the next article, I’ll show you how to force a selection within the Drop Down List.  This will make the page a bit more user friendly, so that’s always worth the extra effort.  I promise, we’ll jump out of code view and start clicking around more: Screenshots and all…  Are you still interested?


Monday, May 24, 2010

Security trimmed list views with ease!

I didn’t know how if this could be done, so I did what came natural.  Poke around 'til I finally get an answer.  Usually I end up with a dead-end but today, I definitely found something of value.  It’s a lot more simple than what I originally thought.  Tools needed: SharePoint Designer and Notepad.  This could all be done within SPD but since it crashes on me, I tend to take my code offline, then paste it back into SPD, right before saving.

So where do we start?  How about cracking open the list that you’d like to create a secure view on.  I needed a way to create a secure view of a Gantt Chart and mash it up with a few other lists.  So since I didn’t know how to make a Gantt chart with a DVWP, I poked around a little.  I created a Gantt Chart view using the GUI.  When you save the view, there is a .aspx page that shows up within the Folder Navigation.  My custom view is cleverly called, PersonalViews.aspx

SPD-FolderNav

Once this view is created, you can open the page up and *reuse* all of that code somewhere else…  So, since I already have a Benchmarking Doc Library that uses custom permissions,  this will be a perfect place for my PersonalViews.aspx page.  After opening the page, click over to the code view and select all of the code.  This is where Notepad comes into play.  I take all of that code and paste it directly into a fresh Notepad .txt file.  That way I have all of that code within another program…  Just a preference, but we all have our ways ;-).  With all of that code, we can now navigate the GUI and delete the view we created.  There’s no need for it anymore and it’s best to delete the view within the GUI.  I’m not sure what happens if you just delete the .aspx page, but to be safe, use the GUI.  Why are we deleting what we just created?  Doesn’t that defeat the purpose?  NO!  We have all of the code that’s needed in Notepad, remember?  What we need to do now is create a new .aspx page within SPD.  I deleted all of the auto generated code:

SPD - NewASPX

We don’t need any of that gunking up our new view.  Now copy all of the code from Notepad into the code view of the .aspx page.  When this page renders, it’ll give you a nasty looking error:

SPD - ListViewError

I thought this was a show stopper, until I saved it in my secure location: Benchmarking Doc Library.  Here only the owners of the site are allowed to view.  I’ve tested logging in as many different users and even if they are allowed to view the Benchmarking Doc Library, if they don’t have explicit rights to this aspx page, they’ll get security trimmed.  List Views can now be security trimmed!!!  Also, you’ll notice within your list, the drop-down for all of the views has a new view.  It’s called whatever you named your aspx page.  However, when someone without rights to the page clicks on the view from the drop down, they’ll soon realize they are in the wrong spot:

Access Denied Error

If you use this and find more purposes for this, please drop a comment.  I’d like to hear about it.