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

Thursday, October 21, 2010

Fix the issue of empty WssId

While I was busy building an app for multiple tagging in sharepoint, I was stuck with a problem involving the method GetWssIdOfTerm() returning empty values if the term has never been used before in the site.
After a few hours of research I found a blog post that helped me with that problem.
I am not too sure who posted it but it helped me a lot.
I had to do a few modifications to the codes but now it works.

The blogspot is here

Enjoy.

Friday, October 15, 2010

Issue with GetWssIdOfTerm() method in sharepoint

I am sure that most sharepoint developers know about the GetWssIdOfTerm() method.
I recently used that method and for some reason it was always returning a null value.
After hours of struggling and screaming, I noticed that the wssId of a term stays null until it has been used at least once, so until you use your term at least once that method will always return a null value.
If I had known that before it would have saved me quite a few hours of screaming.

Monday, October 4, 2010

Retrieving Taxonomies Progrmatically

I recently made a quick google search on how to retrieve taxonomies programatically, and I could not find anything, so I thought I would blog about how to do it.
Get from it what you can.

SPSite thisSite = SPContext.Current.Site;
TaxonomySession session = new TaxonomySession(thisSite);
foreach (TermStore tStore in session.TermStores)
{
    Console.WriteLine("Term Store:" + tStore.Name);
    foreach (Group tGroup in tStore.Groups)
    {
        Console.WriteLine("Group:" + tGroup.Name);
        foreach (TermSet tSet in tGroup.TermSets)
        {
            Console.WriteLine("Term Set:" + tSet.Name);
            foreach(Term term in tSet.Terms)
            {
                Console.WriteLine("Term:" + term.Name);
            }
        }
    }
}

Or you can use this way

TaxonomySession session = new TaxonomySession(siteCollection);
TermStore termStore = session.TermStores[tagsField.SspId];
TermSet termSet = termStore.GetTermSet(tagsField.TermSetId);
myTerm = termSet.Terms[myTermName];

In this scenario tagsField was a taxonomy field that I am trying to update and myTermName is the term name I am trying to get (let me know if you get confused).

Friday, October 1, 2010

Talk to SharePoint Through Its Web Services

Recently I have found out that sharepoint web service are quite powerful and interesting to use.
For anyone interested in learning more you should read this post by Klaus Salchner.