Thursday, December 2, 2010

Hiding the Quick Launch in SharePoint 2010


Hiding the Quick Launch in SharePoint 2010

At times one would really feel no need of the Quick Launch section on few pages or sites i.e. the Team Site, one would really love to use the full width of the page for this one. Luckily the Content Editor Web Part trick which worked in SharePoint 2007 still works in 2010.
To hide the Quick Launch
1. Add a new Content Editor webpart. (Doesn’t matter where you add it)
2. Edit the HTML Source for the newly added Content Editor Webpart
3. In the HTML Source add the following and Click OK.
#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}
[Do not forget to add the style open and close tag as seen in below image due to rendering issues its not showing up]
4. Save the Page. The Quick Launch section should not be visible now.
5. Edit the Just added Content Editor web Part and Under Layout Section Tick the Hidden Check box and Click OK, Which will hide the Webpart from Normal View.
6. This works on any SharePoint 2010 or Foundation 2010 Page and site.

This information comes from The Communicator

Monday, November 22, 2010

Using Javascript to Manipulate a List Form Field

This information was given by Rob Howard
Hi, my name is Rob Howard, and I’m a Program Manager with the SharePoint Designer team. Like several of the other people posting here, I also built many of the Application Templates for Windows SharePoint Services.
If you’re familiar with them, you may have noticed that in several of the application templates we use a bit of Javascript to set default form values based on the query string. Because we found this to be useful in many different cases throughout our applications, I wanted to share our method with you guys so that you can include it in the applications you develop.
When might you use this?
It’s pretty easy to set a field’s default value through the list settings in the browser UI, so why might you need Javascript to set a default field value? The reason is that field default values can only take static values or simple formulae based on the current user or today’s date. If that meets your needs, then I’d definitely recommend sticking with that method. Sometimes, though, you may want the form to fill with default values based on the user’s interaction with the previous page, and that’s exactly where this method comes in.
How does it work?
In short, we add some Javascript to the page that runs when the body is loaded. This Javascript parses the page’s query string, locates the HTML objects that are rendered by the relevant SharePoint fields, and sets their value based on the information in the query string.
getTagFromIdentifierAndTitle
The most important part of our solution is the “getTagFromIdentifier” function. This function finds the HTML element rendered by a given SharePoint FormField control. It takes the following parameters:
  • tagName – The name of the tag rendered in the form’s HTML
  • identifier – The string associated with the SharePoint type of the relevant field
  • title – The value of the relevant HTML tag’s “title” attribute, which also matches the field’s display name
Here’s a partial table of SharePoint column types and their corresponding “identifiers” and “tagNames”:
SharePoint Field TypeidentifiertagName
Single Line of TextTextFieldinput
Multiple Lines of TextTextFieldinput
NumberTextFieldinput
CurrencyTextFieldinput
Choice (dropdown)DropDownChoiceselect
Lookup (single)*Lookupselect
Lookup (multiple)SelectCandidate; SelectResultselect
Yes/NoBooleanFieldinput
*Lookups are a bit more complicated because Lookup FormFields render differently when the target list contains more than 20 items. See the end of the post for an example.
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;
}
fillDefaultValues
Now that we have the HTML elements that we want to set, we need the values with which to set them. In our solution, we wrote the “fillDefaultValues” function, which parses the page’s querystring and then uses the values to set the field defaults.
function fillDefaultValues() {
  var qs = location.search.substring(1, location.search.length);
  var args = qs.split("&");
  var vals = new Object();
  for (var i=0; i < args.length; i++) {
    var nameVal = args[i].split("=");
    var temp = unescape(nameVal[1]).split('+');
    nameVal[1] = temp.join(' ');
    vals[nameVal[0]] = nameVal[1];
  } 
  // Set HTML element default values here
}
_spBodyOnLoadFunctionNames
In most cases SharePoint pages are based on a master page that contains the “body” element. These content pages can’t directly add a function to the body’s onload event. In order to work around this limitation, SharePoint provides the “_spBodyOnLoadFunctionNames” array. When the body is loaded, the onload event handler executes each function whose name is contained in this array. We added “fillDefaultValues” to the array so that it would run when the body’s onload event fires.
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
All Together Now
With the script above, you can set most different field types to any value from the querystring – or any other source that javascript can access. Below is a full example of the script we use to set the default value of a Lookup field based on an ID stored in the querystring. You’ll notice that setting a Lookup field is a bit more complicated than some other field types. The reason is that Lookup FormFields are rendered with different HTML when the target list contains more than 20 items.
Enjoy!
<script type="text/javascript">

// This javascript sets the default value of a lookup field identified
// by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
// identified by <<QUERYSTRING VARIABLE NAME>>


// Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
// <<QUERYSTRING VARIABLE NAME>> with appropriate values.
// Then just paste it into NewForm.aspx inside PlaceHolderMain

_spBodyOnLoadFunctionNames.push("fillDefaultValues");

function fillDefaultValues() {
  var qs = location.search.substring(1, location.search.length);
  var args = qs.split("&");
  var vals = new Object();
  for (var i=0; i < args.length; i++) {
    var nameVal = args[i].split("=");
    var temp = unescape(nameVal[1]).split('+');
    nameVal[1] = temp.join(' ');
    vals[nameVal[0]] = nameVal[1];
  } 
  setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]);
}

function setLookupFromFieldName(fieldName, value) {
  if (value == undefined) return;
  var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);

// 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 (theSelect == null) {
    var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
    ShowDropdown(theInput.id); //this function is provided by SharePoint
    var opt=document.getElementById(theInput.opt);
    setSelectedOption(opt, value);
    OptLoseFocus(opt); //this function is provided by SharePoint
  else {
    setSelectedOption(theSelect, value);
  }
}

function setSelectedOption(select, value) {
  var opts = select.options;
  var l = opts.length;
  if (select == nullreturn;
  for (var i=0; i < l; i++) {
    if (opts[i].value == value) {
      select.selectedIndex = i;
      return true;
    }
  }
  return false;
}

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;
}
</script>


This information was given by Rob Howard

Monday, November 8, 2010

You must use the role management tool to install or configure

I had that error when I tried to install .net framework 3.5 to install office server 2007 with SP1
To fix it is very easy:
1. Click the Start button
2. Right-Click on Computer and select Manage
3. In Server Manager click on Features
4. In features, click on Add features














5. Add the .NET Framework 3 or 3.5 features
And there you go, problem fixed :)

Monday, October 25, 2010

SP2010 forces users to save PDFs – Solution Found!

This wonderful information is given to us by cookie

We’ve recently deployed SP2010 at a new client .Things are dandy, except the users are complaining that they are prompted to save PDFs when they click on them, instead of the PDF opening up in Adobe Acrobat. What?? That seems insane, but it turns out it is “by design” as I found out on Sean’s blog: http://blog.brainlitter.com/archive/2010/05/19/sharepoint-2010-treats-pdf-and-other-file-types-as-insecure.aspx

This worked on the top level site collection ,but not on doc libs on other site collections in the web application, so I saw within this forum post: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/80365b88-937a-4188-85ef-45cbdc2cd10d that someone suggested the following:

“The http header X-Download-Options: noopen is added by the Browser File Handling and the two setting that are in it.  But the Read-only and Edit prompt are driven by SharePoint and a setting in the DOCICON.XML file. If you have added PDF as a Document extension inside the DOCICON.XML you will need to also add an additional attribute in the line and that is opencontrol=”” this seems to stop SharePoint from applying it's header to open the document. <Mapping Key="pdf" Value="icpdf.gif" OpenControl=""/> “


I did this as well but we were still getting prompted.  Oddly enough, if you checked out the document, then you could open the PDF directly. Also, NEW doc libraries on these sites would open PDFs correctly. This is all very strange.

I then tried changing the document library setting to force documents to open in the the client application. (Settings > Advanced Settings > Opening Files in the Browser). Still no luck.

At this point, my instinct was that some setting on the document library, that I could not see from the UI, was not getting properly set when I changed the web application level setting. Well, thanks to Todd Klindt’s blog, http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=214, plus some Powershell wrangling, I was able to find a way to go to the properties of the doc lib and verify that it’s BrowserFileHandling property was still set to “Strict”! 

PS C:\ > Add-PSSnapin Microsoft.SharePoint.Powershell
PS C:\> $site = Get-SPSite(“http://mysubsitecollectionurl”)
PS C:\> $web = $site.OpenWeb()
PS C:\>  $list = $web.GetList(“http://mysubsitecollectionurl/List”);
PS C:\>  $list.browserfilehandling
Strict

No wonder we were still having issues! Using powershell, I was able to set this property to “Permissive”, and my PDFs immediately began opening in Adobe. Whoo hoo!

PS C:\> $list.browserfilehandling = “Permissive” ; $list.update();
PS C:\> $list.browserfilehandling
Permissive

Now I want to be able to go through all my existing doc libs and switch that property. Unfortunately there wasn’t any way to filter out which libraries needed to be switched (manually created ones) and ones that did not (default SharePoint doc libs), so I ended up going through the sites on a case by case basis, mostly driven off the doc lib names b/c we had used site templates to deploy the same doc libs to the different sites.

PS C:> foreach ($list in $rsrWeb.Lists) { if($list.title -match "Documents") { if($list.browserfilehandling -eq "Strict") { $list.browserfilehandling = "Permissive"; $list.update(); $site.url, $list.title, $list.browserfilehandling} }  }
Use the line above to copy into your Powershell window, but let me break it out down below:
foreach ($list in $web.Lists)
{    
     if($list.title -match "Documents")     //return any lists with a title containing “Documents”   
    {        
          if($list.browserfilehandling -eq "Strict")  //if the profile is set to strict       
         {            
               $list.browserfilehandling = "Permissive";           
               $list.update();           
               $site.url, $list.title, $list.browserfilehandling  //print the list url/name for verification        
          }    
     } 
}


Woo hoo!! Hope this helps you out when dealing with WHY THE HECK is SharePoint hating on PDFs??!!

This wonderful information is given to us by cookie