Sharing the same EditForm between different roles

I recently had a client that wanted to show some fields in a form for end users as read only, while Managers, taking a decision, should be able to edit the same fields, all using the same EditForm.aspx.

Ok, so how did I go around getting this to work?

The Managers have Edit permission on the site, while end users have Contribute, this gives the Managers the list permission “Manage Lists”, which end users lacks.

First thing I did was to fire up SPD locating the list and create a new EditForm, let’s call it EditForm2.aspx.
I also created a new DispForm, called DispTrash.aspx (so that I know it should be deleted when I had finished my work).

In your EditForm, locate the top-most field that should be editable to managers, Before its starting <tr> add this:

    <SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageLists" PermissionContext="CurrentSite">
    <table class="trimmedContent">

Here will the fields be listed…

After the last field’s end tag </tr> add this:


So we are wrapping the fields with a Security Trimmed Control and a table. this will give the result that the code inside this Control will be hidden for end users.

Now, right after this end tag of the Security Trimmed Control add this:

    <table class="notTrimmed">

Let’s open DispTrash.aspx in SPD, locate the same fields that you wrapped inside this Security Control. Copy the rows and make sure you get the starting <tr> of the first field and ending </tr> of the last field, so that the HTML don’t get messed up.
Paste this code right after this table’s starting tag.
After the last field’s ending tag </tr>, add this:

</table>, to close this table.

Ok, so what do we have this far?

  1. We have two sets of the same fields, where some are editable and the others are display only.
  2. The editable fields are wrapped in a Trimmed Control and will only be shown for users with ManageLists permissions.
  3. This means that the table with the class “trimmedContent” only will be visible to Managers.
  4. And Managers will see both these sets of fields…this must be taken care of!

Locate this row:
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Add this code right after this row:

// Hide display fields if security trimmed table exists
if ( $( ".trimmedContent" ).length ) {
    $( ".notTrimmed" ).hide();

This code will check if the table with the class of “trimmedContent” is present. If it is, it means that the user is a Manager and we choose to hide the table that contains the display only fields.

Mission accomplished!

My hope is that this will help someone.



Link to media files on file server

Hi everyone!

I had a client a little while ago that had this requirement.

  • In a list it should be as simple as possible for the users to add a link to a media file that is located on a file server.
  • They did have a mapped net work drive and they were only connected to their Intranet while at office or through VPN.
  • The installation is a SharePoint Foundation

My first thought was to add a default value to a URL column so that they only had to add the last part, but that was not possible.

Then I tried to add the default value to a text column and that worked if it was an http-link but not a file-link.

My friend jQuery came to rescue and offered me a solution that came to be like this.

The idea is that the user, besides adding a few other things in this form, only should have to add the file name and file type e.g. “” in a field to build a link to the file on the server.

Ok, so I found a snippet of a JavaScript (I can’t remember where, sorry) that should be added to an aspx-file and when called, would open up a folder on a shared drive. And that my friends was almost what I was looking for, now I only needed to add the functionality to pick up a parameter and open a file in that folder instead.

First I added a new column “MediaLink” of the type URL. This column should be set to be hidden in the forms, but do that a little bit later.

Then I added a new column “MediaFile” of the type Text with a description of what they should be adding, name and type.

By adding this jQuery code to the edit and new forms, the URL to the JavaScript snippet file, and the value of the “MediaFile” is added to “MediaLink”. At the same time it checks if “MediaFile” is empty, if it is it won’t add the text “Link to media” in the column for that item.

<script type="text/javascript">
$(document).ready(function() {
$('input[title=MediaFile]').change(function() {
var value = $(this).val();
$('input[title=MediaLink]').attr({value: 'http://companyweb/SiteName/SitePages/media.aspx?fileName='+(value)});
if ($(value).length < 1){
$('input[name*="ff81$ctl00$ctl00$UrlFieldDescription"]').attr({value: 'Link to media'});

Be sure to change the URL to media.aspx if you will put it somewhere else. The last part of the attribute “name” you could find by viewing the source of the page, that is before you hide it of course 🙂

Ok so what about that JavaScript snippet, what should we do with that and where is it?

As you can see in the code above I add the parameter “fileName” to the URL of the “media.aspx“. This is the file that should have this snippet that I have been talking so much about 🙂

It looks like this.

  <script type="text/javascript">
//Get querystring
var queryString = window.location.href.split("?")[1];
    var fileName = queryString.split("=")[1];
    // mapped network drive
    var drive = "file://Server/share"
    // folder within the mapped network drive
var folder = "/Folder1/Folder2/Folder3" + folder + fileName, "File");

So, simply add this code to a file called “media.aspx” and put the file in “SitePages”. Be sure to change the variables “drive” and “folder” so that they fit your environment.

I had a talk to Marc D Anderson about this and he gave me a few ideas that I will try to improve this further. When I have, I will update this post with these improvements.

I hope this will help someone!

CU in Vegas in a couple of weeks!