Wednesday, March 9, 2011

SharePoint 2010 and Adobe PDF

The following post is an update from the original ‘SharePoint 2007 and Adobe PDF‘ post written in 2007. These notes are based on SharePoint 2010 Beta 2 (made publicly available in November 2009). Once the product has officially launched on 12 May 2010, an update will be posted if any changes are made to the process. The process is very similar to SharePoint 2007, with minor changes to folder location (14 instead of 12) and a slightly different administration user interface in the browser.
SharePoint 2010 and Adobe PDF
SharePoint Server 2010, like its predecessors, includes indexing and search capabilities. But what doesn’t come out of the box is the ability to index and search for PDF documents. PDF is a format owned by Adobe, not Microsoft. If you want to be able to find Adobe PDF documents, or have the PDF icon appear when viewing PDF files in a SharePoint document library (see image above), you will need to set it up for yourself. This post describes how to.
  1. Download and install Adobe’s 64-bit PDF iFilter*1http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025
  2. Download the Adobe PDF icon (select Small 17 x 17) – http://www.adobe.com/misc/linking.html
    1. Give the icon a name or accept the default: ‘pdficon_small.gif’
    2. Save the icon (or copy to) C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES
  3. Edit the DOCICON.XML file to include the PDF icon
    1. In Windows Explorer, navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML
    2. Edit the DOCICON.XML file (I open it in NotePad, you can also use the built-in XML Editor)
    3. Ignore the section <ByProgID> and scroll down to the <ByExtension> section of the file
    4. Within the <ByExtension> section, insert <Mapping Key=”pdf” Value=”pdficon_small.gif” /> attribute. The easiest way is to copy an existing one – I usually just copy the line that starts <Mapping Key=”png”… and replace the parameters for Key and Value (see image below)
    5. Save and close the file
      SharePoint 2010 and Adobe PDF DOCICON.XML
  4. Add PDF to the list of supported file types within SharePoint
    1. In the web browser, open SharePoint Central Administration
    2. Under Application Management, click on Manage service applications
    3. Scroll down the list of service apps and click on Search Service Application
    4. Within the Search Administration dashboard, in the sidebar on the left, click File Types
    5. Click ‘New File Type’ and enter PDF in the File extension box. Click OK
    6. Scroll down the list of file types and check that PDF is now listed and displaying the pdf icon.
    7. Close the web browser
  5. Stop and restart Internet Information Server (IIS)*2 Note: this will temporarily take SharePoint offline. Open a command line (Start – Run – enter ‘cmd’) and type ‘iisreset’
  6. Perform a full crawl of your index. Note: An incremental crawl is not sufficient when you have added a new file type. SharePoint only indexes file names with the extensions listed under File Types and ignores everything else. When you add a new file type, you then have to perform a full crawl to forcibly identify all files with the now relevant file extension.
That’s it. If you now perform a search, PDF files should be displayed in results where they match the search query, along with the PDF icon on display in results. The icon should also be visible in any document libraries that contain PDF files.
* Additional Notes:
  1. At time of writing, Adobe has published PDF iFilter 9 for 64-bit applications, tested on SharePoint 2007 but not yet listed as tested on SharePoint 2010. So far, it is working fine on my builds of SharePoint 2010 (Beta versions)
  2. When setting this up, I initially just restarted the search service rather than IIS but found myself locked out of SharePoint. Resetting IIS fixed it. I don’t know for certain if you also need to restart the search service. Will test on the next build and update here.
  3. As with SharePoint 2007, there are alternative PDF ifilters. The most well known is Foxit Pro – http://www.foxitsoftware.com/. Rumoured to perform indexing faster than using Adobe’s iFilter. I can’t comment, I haven’t tested it. Given PDFs don’t change (they are usually PDFs specifically to not be edited) they are only indexed when first uploaded or when you perform a full crawl. Most organisations should primarily be performing incremental crawls – updating the index with content that has been added or changed rather than re-indexing everything


Information kindly given by Sharon Richardson

Friday, February 25, 2011

Access denied while doing a restore

I recently faced the problem of having powershell and normal command line stsadm giving me the "Access denied" error when trying to restore a sharepoint site.
Here is how I fixed it.
1. Run cmd or powershell as an administrator
2. Make sure that you are a farm admin
3. Make sure the user belongs to the following groups:
  • Administrators
  • IIS_WPG 
  • WSS_WPG
  • WSS_ADMIN_WPG 
  • WSS_RESTRICTED_WPG
And that fixed my issue.

Monday, January 10, 2011

Call your custom CSS in sharepoint

When you wish to use your own custom Css in sharepoint but do not know how to call it in your master page, use the following line in the <head> of your master page:


<SharePoint:CssRegistration name="<%$SPUrl:~SiteCollection/Style Library/~language/Core Styles/Style.css%>" runat="server"/>


"~language" must be changed to the language in which your style is, i.e: en-us


or you can use the following line:


<SharePoint:CssRegistration name="~url of stylesheet" runat="server"/>

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