Dailycode.info

Short solution for short problems

Open document in Edit mode: DispEx

Frustrating, this is what Sharepoint sometimes can be. Today I realised that the workflow I created on a document library (in Sharepoint Designer) is not able to fulfill our needs.

The story:

When you assign a Todo item, or a create task, the system creates a link to the document. When a user clicks on the link, a read only version is opened in a browser. The task should be review. So if the reviewer open the task, he clicks on the link to review the document. Then he makes changes and when he is finished, he clicks Ctrl-S, nothing happens. In the menu, only the save-as button is enabled. When he browses for the correct document library and tries to save the document, the system asks him to overwrite. He chooses Yes. Then a friendly pop up tells him the document is a read only version. Hahaha he smiles, I can start over. This is not what I had in mind. I was hoping the document could be opened(not in a browser but in Word) and saved.

So as a solution, I choose to open a link to a webpart, on which I created a link t the document. Using the DispEx function, the document is opened in Word and the reviewer only needs to press Ctrl-S and it is saved as a new version on the correct place.

Here the code:

public class OpenDoc : WebPart
    {
        string sSOPURL = null;
        string sSOPName = null;
 
        private string GetSOP()
        {
            if (String.IsNullOrEmpty(sSOPName))
            {
                sSOPName = this.Page.Request.QueryString["qSOPName"];
                if (String.IsNullOrEmpty(sSOPName))
                {
                    sSOPName = "noSOPsel";
                }
            }
            return sSOPName;
        }
 
        private string GetSOPURL()
        {
            if (String.IsNullOrEmpty(sSOPURL))
            {
                sSOPURL = this.Page.Request.QueryString["qSOPURL"];
                if (String.IsNullOrEmpty(sSOPURL))
                {
                    sSOPURL = "noSOPurl";
                }
            }
            return sSOPURL;
        }
 
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            try
            {
                if (GetSOP() == "noSOPsel")
                {
                    writer.Write("<br>");
                    writer.Write("<br>");
                    writer.Write("<center>");
                    writer.Write("To open an SOP, click below");
                    writer.Write("<br>");
                    writer.Write("<br>");
                    writer.Write("</center>");
                }
                else
                {
 
                    writer.Write("<br>");
                    writer.Write("<br>");
                    writer.Write("<center>");
                    string url = GetSOPURL();
 
                    if (url.EndsWith("doc") || url.EndsWith("docx"))
                    {
			//This is were we write the code to open the document in edit mode
                        writer.Write("<A onfocus=\"OnLink(this)\" HREF=" + url + " onclick=
\"return DispEx(this,event,'TRUE','FALSE','TRUE','','0','SharePoint.OpenDocuments','','','',
'21','0','0','0x7fffffffffffffff')\">" + GetSOP() + "</A>");
                    }
                    else
                    {
                        writer.Write("<A target='_blank' HREF='" + url + "'>" + GetSOP() + "</A>");
                    }
                    writer.Write("<br>");
                    writer.Write("<br>");
 
                    writer.Write("<br>");
                    writer.Write("<br>");
                    writer.Write("</center>");
                    RenderChildren(writer);
 
                }
 
            }
            catch (System.Security.SecurityException x)
            {
                writer.Write("Sec Error: " + x.ToString());
            }
            catch (Exception er)
            {
                writer.Write("Error: " + er.Message);
            }
        }
    }

In the workflow I create a task for the reviewers, in the description I put a link to a page holding this webpart. The document URL and Name are provided as querystrings to this page.


How to configure pdf filter for WSS 3.0?

Follow these steps to configure the ifilter: 

First, you need to download the Adobe PDF IFilter 6.0, which you can find at this URL.  You should also get hold of a suitable Icon to use with PDFs, so that when they are listed in a document library they are easily recognisable.  There is a 17 x 17 one available on the Adobe web site here.

Once you’ve downloaded the IFilter, install it on your WSS 3.0 server, and then follow the instructions on registry settings in Microsoft KB Article 927675.  I’ve always found that providing the Adobe IFilter installed properly, the only setting I need to add is the Search Extensions. Also note re stopping and re-starting the search service at the end of this article.
Now you need to set up the Icon file. 

If you downloaded the icon file in step 1 above, you will have a file called pdficon_small.gif.  You need to copy this onto your WSS 3.0 server, into drive:\Program Files\Common FIles\Microsoft Shared\Web Server extensions\12\TEMPLATE\IMAGES.

Next you need to edit the XML file which WSS uses to link file extensions to icons.  This file is called DOCICON.XML and is located at drive:\Program Files\Common FIles\Microsoft Shared\Web Server extensions\12\TEMPLATE\XML.  Navigate to that folder and locate the file.  I would suggest making a backup copy first, then opening the file in NotePad.  You need to add a mapping key for PDFs at the bottom of the file, above the </ByExtension> closing tag.  The new key will be <Mapping Key=”pdf” Value=”pdficon_small.gif” OpenControl=”"/>  (note that XML is case sensitive so make sure you use same case as previous entries).  Then save the file.

If you already have PDFs uploaded to your WSS server I would recommend starting a full crawl.  You can do the with STSAdm, the command syntax is Stsadm -o spsearch -action fullcrawlstart .

When you notice that pdf documents are crawled and showed by the WSS search, but still the icon doesn't show up. If you triple checked the DOCICON.xml file and if the image is correct and IISRESET doesn't change a bit, then maybe this can help:

Create a new site collection. check if the pdf icons are showed in this new collection. Now return to the old site collection, normally the icons should now show up. In my case this helped!


Search service won't start

After you installed WSS on your server, you start configuring. At a point you want to configure the search service, but you can't find the place where you need to configure this.

In your central administration, go to the home page. Then you will find under server topology the name of the server where you installed WSS on. Click on the name and you will be forwarded to the page where you can configure the services on the server. You will notice that the search service is stopped.

When you try to configue this service, it could happen that a general error message is shown. When you click help, you'll get the default WSS help with nothing on this problem. It's hard to google for this problem because you can't find a good error explanation.

When you were lucky and found this post. Try to add the domains before the user names. In my case it solved the problem. Even if it is a local user, place the computer name before the user. To bad WSS doesn't give a simple error like: "unknown user". You don't have to do this for the SQL user when you use SQL authentication.