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"))
                    {
                        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.