Feeds:
Posts
Comments

Have you ever received a message along the lines of error reading file when trying to open a file in SharePoint Designer (SPD)? Last week I was working on a copy of a NewForm.aspx file. My customer wanted significant changes to the form. Since the form was already live, I checked the file out, made all the changes, tested and then checked the file back in. Everything was great until after the check in. When I tried to make some additional edits by checking the file back out and then opening it, I got an error reading file message. YIKES!!!

If this happens to you, don’t despair! Here’s the fix. First make a copy of the file in SPD so you have a backup. Then in SPD right click on the file and select Open
With/ SharePoint Designer (Open as Text). The file will open and you will see many, many blank lines that are adding unnecessary bulk (in my case I had over 195,000 blank lines interspersed along with my code). At this point you can now delete all the blank lines, save your file and all will be good. Alternately, you can copy all the code and place it in a local file on your computer. Then you can edit out the blank lines in the local file and copy the updated code back into the file in SPD. This alternate approach is a little faster.

A little while back I created a post about how to filter a lookup list used on a New or Edit form. The process was a little involved but worked beautifully except when you needed attachments to work (the attachment problem is a known issue when customizing an Edit or New form). In that post I also mentioned that I developed a way to do the same thing using JavaScript but because the original form is left intact, the attachments still work.

As references, I used the starkwell’s post halfway down the page as my starting point. Because his post was for 2003, I found some differences and had to make some significant modifications to make this work. I also grabbed some code from MS SharePoint blog “Using Javascript to Manipulate a List Form Field“.

Here are the steps:

  1. In a browser, create a list (ClassJavascriptLookup in my example) that uses a lookup column. In my case the lookup column is InstructorLookup. The column displayed is InstructorName and the filtering will be done such that only the Instructors that have a Status of Active will be shown.

  2. Using SharePoint Designer, expand the files under the list you are using. Make a backup of the form (EditForm.aspx or NewForm.aspx) you will be editing just in case. Check out the file and then double click on the it to open.

  3. Place your cursor right after the existing form. You can do this by selecting the existing form by clicking on it (as below) and then hitting your right arrow key.

  4. From the top menu select Data View/ Insert Data View.

  5. Click the link “Click a data source in the…”

  6. In the Data Source Library tab on the right side, select the list you want for the filtered lookup. Then click on Show Data.

  7. Select the field you want to show in the dropdown.

  8. Insert Selected Fields as… Multiple Item View

  9. Click on the arrow in the upper right of the inserted data view to display the Common Data View Tasks menu.

     

  10. Set the filter to pull only the items you want to show in the dropdown.

  11. Set the sort order.

  12. Click on Change Layout task. Under the Layout tab, choose the style for “The dropdown menu of titles style…”

     

    Click Yes on the popup that displays.

  13. Make sure you have Split mode showing for SharePoint Designer.

  14. Click on the dropdown that is now showing in the Design Window. The associated code will be highlighted in the Code pane.

  15. In the highlighted code displayed for the newly created dropdown, find the line:

    <select name=”ID” size=”1″>

            <option selected=”true” value=”0″>Choose One…</option>

     

    Change the line to the following by commenting out the 2nd line and changing from name to id:

    <select id=”FilteredLookupList” size=”1″>

            <!–<option selected=”true” value=”0″>Choose One…</option>–>

     

  16. Find the line below for the new dropdown:

        <xsl:template name=”dvt_1.rowview”>

     

    Change it from this (note you will probably have something other than InstructorName):

        <xsl:template name=”dvt_1.rowview”>

            <option>

                <xsl:value-of select=”@InstructorName” />

            </option>

        </xsl:template>

    To this:

        <xsl:template name=”dvt_1.rowview”>

            <xsl:variable name=”SelectValue” select=”@ID”/>

            <option value=”{$SelectValue}”>

                <xsl:value-of select=”@InstructorName” />

            </option>

        </xsl:template>

  17. Paste in the following code directly after the PlaceHolderMain tag (you will need to change Instructor to the name of your Lookup column):

     

    <script language=”javascript” type=”text/javascript”>

     

    _spBodyOnLoadFunctionNames.push(“callFillLookupValues”);

     

    function callFillLookupValues() {

        fillLookupValues(“FilteredLookupList”, “Instructor”);    

    }

     

    </script>

  18. Next you will need to add the method for filLookupValues() and a supporting method. You can add these to your master page or a separate JavaScript file as desired especially when considering reuse. However, for simplicity here, let’s just add these to our existing page for now. Directly after the function callFillLookupValues() and before the closing script tag you added in the previous step, add the following code:

     

    function fillLookupValues(filterDataView, lookupToFilter) {

                var data = document.getElementById(filterDataView);

                var lookup = getTagFromIdentifierAndTitle(“select”, “Lookup”, lookupToFilter);

                var selectedText = “”;

                

                // if theSelect is null, it means that the target list has more than

                // 20 items, and the Lookup is being rendered with an input element

                if (lookup == null) {

                 var theInput = getTagFromIdentifierAndTitle(“input”,”",lookupToFilter);

                 selectedText = theInput.value;

                 theInput.choices = “”;

                 var filteredChoices = “”;

                 for (i=0;i<data.options.length;i++)

                    {

                        var optionText = data.options[i].text;

                        var optionValue = data.options[i].value;

                        if (i>0)

                        {

                            filteredChoices = filteredChoices + “|”;

                        }

                         filteredChoices = filteredChoices + optionText + “|” + optionValue ;

                    }

                    theInput.choices = filteredChoices ;

             }

                else

                {

                    selectedText = lookup.options[lookup.selectedIndex].text;

                    //alert(data.innerHTML);

                    lookup.innerHTML = “”;

                    for (i=0;i<data.options.length;i++)

                    {

                        var optionText = data.options[i].text;

                        var optionValue = data.options[i].value;

                        lookup.options[i]=new Option(optionText, optionValue, false, (optionText == selectedText));

                    }

                }    

            }

            

            function getTagFromIdentifierAndTitle(tagName, identifier, title) {

                 var len = identifier.length;

                 var tags = document.getElementsByTagName(tagName);

                 for (var i=0; i < tags.length; i++) {

                     var tempString = tags[i].id;

            
     

                     if (tags[i].title == title && (identifier == “” || tempString.indexOf(identifier) == tempString.length – len)) {

                     return tags[i];

                     }

                 }

                 return null;

            }

  19. Hide the dropdown you added from being displayed on the page by adding style=”display:none;” to the line you previously changed in Step 15 above. Save your changed form.

     

    <select id=”FilteredLookupList” size=”1″ style=”display:none;”>

     

  20. Go back to your list in the browser. Open the form you changed (New or Edit). Now you will see your lookup with the filtered values. In my case only Active Instructors are shown.

  21. A couple of quick notes:
    1. This should also be compatible in Firefox thanks to a colleague of mine, Jim Wilt, who made a couple small tweaks (.innerText to .text and name to id).
    2. The time it takes for your filter to be applied may be affected by where you place your JavaScript (which file).

Frequently I get requests on how to hide the breadcrumb navigation links on a page in SharePoint. For a single page, you can add a content editor web part to the page and then add the following “code” in the Source Editor.

<style type=”text/css”>

#ctl00_PlaceHolderTitleBreadcrumb_ContentMap {display=none;}

</style>

If you want to hide the breadcrumbs on all pages, you can add the code to the master page or an alternate css.    

(REPOSTED FROM MY OLD BLOG) One question I get asked all the time is how to hide the View All Site Content link from the Quick Launch navigation in SharePoint. Unfortunately, there is no option under Site Settings to do this. Instead, the easiest way is to open SharePoint Designer and edit the default.master page (located under _catalogs/masterpage).

To edit the page, first right click on the file and click Check Out. Then double click on the file to open it. Make sure to view the file in the Split mode (located at the bottom of the screen)


At this point you have two options: 1) hide the View All Site Content link for everyone or 2) hide the View All Site Content link for everyone who does not have Full Control to the site. I prefer the second option because it gives administrators the ability to still have access to the link.

Option 1 – Hide View All Site Content for everyone:

  • Click on the View All Site Content link in the Design view. This will select the Sharepoint:SPSecurityTrimmedControl.
  • In the Tag Properties pane (typically located in the lower left), change the Visible Property to False


Option 2 – Hide View All Site Content for anyone who does not have Full Control:

  • Click on the View All Site Content link in the Design view. This will select the Sharepoint:SPSecurityTrimmedControl.
  • In the Tag Properties pane (typically located in the lower left), change the PermissionsString Property to ManageWeb


Save the page and remember to Check In the file.

(REPOSTED FROM MY OLD BLOG) We had a site that needed to have two different custom EditForm.aspx pages. Each custom form was based off the original EditForm.aspx page (this is the recommended approach and can be done by saving “As”). One was set to be used as the default edit form (List Properties /Supporting Files tab). The other was to be accessed using a custom link from a custom page (e.g. from a Dataview page). Each custom edit page was created by hiding the original List Form Web Part to avoid breaking the list.

The problem occurred when clicking on a link on the Dataview page. Rather than going to the second custom edit form, the link brought up the default edit form. Somewhere, a redirect was taking place.

After a lot experimenting, I found that not only do you need hide the original List Form Web Part but you also need to set the ControlMode to Display. Here are the 2 lines of code that need to be modified in the original List Form Web Part:

Change:

<ControlMode xmlns=”http://schemas.microsoft.com/WebPart/v2/ListForm”>Edit</ControlMode>

To:

<ControlMode xmlns=”http://schemas.microsoft.com/WebPart/v2/ListForm”>Display</ControlMode>

Change:

<IsVisible>true</IsVisible>

To:

<IsVisible>false</IsVisible>

(REPOSTED FROM MY OLD BLOG) I had a client who was trying to access a customized datasheet view in WSS 3.0 and received the error “A datasheet component compatible with Windows SharePoint Services is not installed.” The only option that was given was to display the page in the standard view. After a little investigation, I found the client only had Office 2003 available. To resolve the issue, I had her install the SharePoint components which are not included in the default installation of Office 2003. To do this, go to Add/Remove Programs (Programs and Features in Vista). Select the Microsoft Office installation and click on Change. Click Advanced and then go to Office Tools. Select SharePoint Services Support and click Run From My Computer.

(REPOSTED FROM MY OLD BLOG) If you’re involved at all with changing the look and feel of SharePoint sites, you will find a couple of browser add-ons very useful for understanding page layouts and styles. Say goodbye to right-click View source!

For Firefox you won’t be able to live without Firebug. Besides viewing page HTML and CSS through your browser, you can also test out inline edits without affecting the original source. To use you simply right click any item in the browser and select “Inspect Element”.


For Internet Explorer you will find DebugBar a necessity. Basically you drag a target icon onto any element within the browser to view its attributes and values.

(REPOSTED FROM MY OLD BLOG) Ever had a problem with the html generated by the out-of-the-box Content Editor web part where centered text created in Internet Explorer doesn’t display as centered text in Firefox? Have you ever seen where content created in IE overlaps when displayed in Firefox? Ever tried to use the Content Editor web part from Firefox? Have you become frustrated that the Content Editor web part is basically not cross- browser compatible? Have you consider using third party web parts as a work around but then dreaded the whole server deployment and maintenance issue (if you even have access to the server)?

Well, last week one of my partners introduced me to a wonderful Firefox browser add-on that addresses these issues by producing cross-browser compatible html. The add-on is called WriteArea and can be downloaded from here. Besides being very simple to use, there is no server deployment because it is a browser (client) add-on.

After installing WriteArea, navigate to a Content Editor web part on your SharePoint site to get started. In Firefox, open the tool pane and right click in the “To add content, type…” textbox. From the menu displayed, select “Edit in a Write Area”.


 In the displayed WriteArea editing tool, enter your content and click the Save button.


Finish up by clicking Apply or OK in the Content Editor Web Part tool pane.

Older Posts »